From 1109132f09d75da9a28b649c7677bb6ce07c40c0 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:41:45 -0500 Subject: initial commit --- .../objetos_globales/array/@@iterator/index.html | 89 ++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 files/es/web/javascript/referencia/objetos_globales/array/@@iterator/index.html (limited to 'files/es/web/javascript/referencia/objetos_globales/array/@@iterator') diff --git a/files/es/web/javascript/referencia/objetos_globales/array/@@iterator/index.html b/files/es/web/javascript/referencia/objetos_globales/array/@@iterator/index.html new file mode 100644 index 0000000000..65ac581204 --- /dev/null +++ b/files/es/web/javascript/referencia/objetos_globales/array/@@iterator/index.html @@ -0,0 +1,89 @@ +--- +title: 'Array.prototype[@@iterator]()' +slug: Web/JavaScript/Referencia/Objetos_globales/Array/@@iterator +tags: + - Array + - ECMAScript 2015 + - Iterator + - JavaScript + - Prototipo + - Referencia + - metodo +translation_of: Web/JavaScript/Reference/Global_Objects/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ónEstadoComentario
{{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

+ + -- cgit v1.2.3-54-g00ecf