Javascript Array [@@iterator]()

Introduction

The array @@iterator property is for iterating array element.

arr[Symbol.iterator]()
var arr = ['a', 'b', 'c', 'd', 'e'];
var eArr = arr[Symbol.iterator]();
for (let letter of eArr) {
  console.log(letter);//  ww w .  j  av a 2 s  .c o  m
}

Alternative iteration

var arr = ['a', 'b', 'c', 'd', 'e'];
var eArr = arr[Symbol.iterator]();
console.log(eArr.next().value); // a
console.log(eArr.next().value); // b
console.log(eArr.next().value); // c
console.log(eArr.next().value); // d
console.log(eArr.next().value); // e



PreviousNext

Related