Array.prototype[@@iterator]()
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
Ejemplos
Iteración usando el bucle for...of
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
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 Language Specification # sec-array.prototype-@@iterator |
Compatibilidad con navegadores
BCD tables only load in the browser