JavaScript - Arrays - entries

javascript-arrays

// JavaScript - Array.prototype.entries:
The entries() method returns a new Array Iterator object that contains the 
key/value pairs for each index in the array.

var a = ['a', 'b', 'c'];
var iterator = a.entries();

console.log(iterator.next().value); // [0, 'a']
console.log(iterator.next().value); // [1, 'b']
console.log(iterator.next().value); // [2, 'c']

var a = ['a', 'b', 'c'];
var iterator = a.entries();

for (let e of iterator) {
  console.log(e);
}
// [0, 'a']
// [1, 'b']
// [2, 'c']
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License