Array.prototype[@@iterator]()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since May 2018.

El valor inicial de la propiedad @@iterator es el mismo objeto de función que el valor inicial de la propiedad values().

Sintaxis

arr[Symbol.iterator]()

Valor de retorno

El valor inicial dado por el iterador values(). Por defecto, usar arr[Symbol.iterator] devolverá la función values().

Ejemplos

Iteración usando el bucle for...of

js
var arr = ["w", "y", "k", "o", "p"];
var eArr = arr[Symbol.iterator]();
// nuestro navegador debe ser compatible con el bucle for..of
// y variables let-scoped en bucles for
for (let letter of eArr) {
  console.log(letter);
}

Iteración alternativa

js
var arr = ["w", "y", "k", "o", "p"];
var eArr = arr[Symbol.iterator]();
console.log(eArr.next().value); // w
console.log(eArr.next().value); // y
console.log(eArr.next().value); // k
console.log(eArr.next().value); // o
console.log(eArr.next().value); // p

Especificaciones

Specification
ECMAScript® 2025 Language Specification
# sec-array.prototype-%symbol.iterator%

Compatibilidad con navegadores

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
[Symbol.iterator]

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Uses a non-standard name.
Has more compatibility info.

Ver también