Array.prototype.entriesintermediateconst arr = ['x', 'y', 'z']
const pairs = [...arr.entries()]
pairs // β [[0,'x'], [1,'y'], [2,'z']]Spread entries() into an array to convert it to an array of [index, value] pairs.
The iterator returned by entries() can be consumed step by step. You can use reduce on the array from the iterator to rebuild the original array from its entries.
Challenge: Implement rebuildFromEntries(arr) that iterates over arr.entries() and rebuilds the array using reduce.
rebuildFromEntries([10, 20, 30]) // β [10, 20, 30]