Array.prototype.entriesintermediateconst fruits = ['apple', 'banana', 'cherry']
for (const [i, v] of fruits.entries()) {
console.log(i, v) // 0 apple, 1 banana, 2 cherry
}Use entries() with for-of destructuring to loop over both the index and value of each element.
Iterating over entries() gives you both the index and the value at each step. This is helpful when you need both without maintaining a separate counter.
Challenge: Implement getIndexValuePairs(arr) that returns an array of [index, value] pairs from ['a', 'b', 'c'].
getIndexValuePairs(['a', 'b', 'c']) // β [[0, 'a'], [1, 'b'], [2, 'c']]