1, the arguments

Arguments is an array-like object corresponding to the arguments passed to the function.

Arguments objects are local variables available in all (non-arrow) functions. You can use arguments objects to refer to function arguments in functions. This object contains each argument passed to the function, the first at index 0. For example, if a function passes three arguments, you can refer to them as follows:

arguments[0]
arguments[1]
arguments[2]
Copy the code

The Arguments object is not an Array. It is similar to Array, but does not have any Array attributes other than the Length attribute and index element. For example, it has no POP method. But it can be converted to a real Array:

var args = Array.prototype.slice.call(arguments);
var args = [].slice.call(arguments);

// ES2015
const args = Array.from(arguments);
const args = [...arguments];
Copy the code
Common class arrays include:
  • HTMLCollection getElementsByTagName/ClassName ()
  • The nodeList that querySelector gets

2. Does forEach return work? How do I break the forEach loop?

Interrupt method:

  • Use try to monitor code blocks and throw exceptions where interrupts are needed.

  • The official recommendation (substitution) : replace forEach with every and some. Every terminates the loop when it encounters return false. Some terminates the loop when it hits return True