Array.prototype.entriesintermediateconst arr = [10, 20, 30]
for (const [i, v] of arr.entries()) {
if (v === 20) console.log('found at', i) // found at 1
}Use entries() to find both the index and value when searching through an array.
By iterating over entries(), you can find the first [index, value] pair where the value matches a condition β useful when you need both the index and the value.
Challenge: Implement findIndexOf(arr, val) that uses entries() to return the first [index, value] pair where the value equals val, or null if not found.
findIndexOf(['a', 'b', 'c'], 'b') // β [1, 'b']
findIndexOf(['a', 'b', 'c'], 'z') // β null