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 septiembre de 2016.
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® 2026 Language Specification> # sec-array.prototype-%symbol.iterator%> |
Compatibilidad con navegadores
Loading…