Hey - here is a cool little thing you can do with es6!

Iterating through an array and using both the element and the index of the element is a pretty useful thing. Here is a way to do it with the Array.prototype.forEach() method:

var arr = ['a', 'b', 'c'];
arr.forEach( (elem, index) => {
    console.log('index = '+index+', elem = '+elem);
});
// Output:
// index = 0, elem = a
// index = 1, elem = b
// index = 2, elem = c

well, in case you are just over the forEach method, you can pull some fancy moves with the the es6 for...of loop - this loop supports iterating over iterable objects (including Array, Map, Set, String, TypedArray, arguments object). You can create an iterable containing index-element pairs by using another new es6 feature, Array.prototype.entries(). You can combine this cool new method with another big one people are hyped on, destructuring.

const arr = ['a', 'b', 'c'];
for (const [index, elem] of arr.entries()) {
    console.log(`index = ${index}, elem = ${elem}`);
}

While this looks newer, it is not as performant as the earlier example. I’ll probably keep doing it with forEach tbh. Peace!