The entries() method

suggest change

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

const letters = ['a','b','c'];

for (const[index,element] of letters.entries()) {
  console.log(index,element);
}

result

0 "a"
1 "b"
2 "c"

The iterator includes empty slots as values of undefined, unlike array methods such as forEach(), which skip empty slots.

Portions of this content from Array.prototype.entries by Mozilla Contributors licensed under CC-by-SA 2.5

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents