Array.prototype.lastIndexOfintermediateconst arr = [4, 2, 4, 2, 4]
arr.indexOf(4) // β 0 (first)
arr.lastIndexOf(4) // β 4 (last)Use lastIndexOf() instead of indexOf() when you need the position of the last occurrence.
If indexOf and lastIndexOf return different indices for the same value, the value appears more than once in the array. This is a neat way to check for duplicates without iterating manually.
Challenge: Implement hasMultiple(arr, val) that returns true when val appears more than once.
hasMultiple([1, 2, 3, 2], 2) // β true
hasMultiple([1, 2, 3], 2) // β false