arguments[@@iterator]()

The [@@iterator]() method of arguments objects implements the iterable protocol and allows arguments objects to be consumed by most syntaxes expecting iterables, such as the spread syntax and for...of loops. It returns an array iterator object that yields the value of each index in the arguments object.

The initial value of this property is the same function object as the initial value of the Array.prototype.values property (and also the same as Array.prototype[@@iterator]).

Syntax

js

arguments[Symbol.iterator]()

Return value

The same return value as Array.prototype.values(): a new iterable iterator object that yields the value of each index in the arguments object.

Examples

Iteration using for...of loop

Note that you seldom need to call this method directly. The existence of the @@iterator method makes arguments iterable, and iterating syntaxes like the for...of loop automatically calls this method to obtain the iterator to loop over.

js

function f() {
  for (const letter of arguments) {
    console.log(letter);
  }
}
f("w", "y", "k", "o", "p");

Specifications

Specification
ECMAScript Language Specification
# sec-createunmappedargumentsobject
ECMAScript Language Specification
# sec-createmappedargumentsobject

Browser compatibility

BCD tables only load in the browser

See also