Array.prototype[@@iterator]()
O valor inicial da propriedade @@iterator
é o mesmo objeto função que o valor inicial da propriedade values()
.
Sintaxe
arr[Symbol.iterator]()
Exemplos
Iteração usando laço for...of
js
var arr = ["w", "y", "k", "o", "p"];
// seu navegador deve suportar laço for..of
// e variáveis de escopo let em laços for
for (let letter of arr) {
console.log(letter);
}
Iteração 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
Especificações
Especificação | Status | Comentário |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.prototype[@@iterator]()' in that specification. |
Padrão | Definição inicial. |
ECMAScript (ECMA-262) The definition of 'Array.prototype[@@iterator]()' in that specification. |
Padrão em tempo real |
Compatibilidade com navegadores
BCD tables only load in the browser