--- title: Array.prototype[@@iterator]() slug: Web/JavaScript/Reference/Global_Objects/Array/@@iterator tags: - Array - ECMAScript 2015 - Iterator - JavaScript - Prototipo - Referencia - metodo translation_of: Web/JavaScript/Reference/Global_Objects/Array/@@iterator original_slug: Web/JavaScript/Referencia/Objetos_globales/Array/@@iterator ---
{{JSRef}}

El valor inicial de la propiedad @@iterator es el mismo objeto de función que el valor inicial de la propiedad {{jsxref("Array.prototype.values()", "values()")}}.

Sintaxis

arr[Symbol.iterator]()

Valor de retorno

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

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

Especificación Estado Comentario
{{SpecName('ES2015', '#sec-array.prototype-@@iterator', 'Array.prototype[@@iterator]()')}} {{Spec2('ES2015')}} Definición inicial..
{{SpecName('ESDraft', '#sec-array.prototype-@@iterator', 'Array.prototype[@@iterator]()')}} {{Spec2('ESDraft')}}  

Compatibilidad con navegadores

{{Compat("javascript.builtins.Array.@@iterator")}}

Ver también