Array.prototype.lastIndexOfadvancedconst arr = [1, 2, 1, 2, 1]
const indices = []
let i = arr.lastIndexOf(1)
while (i !== -1) { indices.push(i); i = arr.lastIndexOf(1, i - 1) }
// indices β [4, 2, 0]Use lastIndexOf() in a loop to collect all positions of a value, from last to first.
By repeatedly calling lastIndexOf with a decreasing fromIndex, you can collect every index where a value appears β all without using filter or reduce.
Challenge: Implement allIndices(arr, val) that returns an array of all indices where val appears, in ascending order.
allIndices([1, 2, 1, 3, 1], 1) // β [0, 2, 4]
allIndices([1, 2, 3], 9) // β []