This function finds the index of the last occurrence of a specified value in an array.
JavaScript:
let lastIndex = (arr, value) => arr.lastIndexOf(value);
// Example
console.log(lastIndex([1, 2, 3, 2, 1], 1)); // 4
console.log(lastIndex(['a', 'b', 'c', 'b', 'a'], 'a')); // 4
TypeScript:
let lastIndex = (arr: T[], value: T): number => arr.lastIndexOf(value);
// Example
console.log(lastIndex([1, 2, 3, 2, 1], 1)); // 4
console.log(lastIndex(['a', 'b', 'c', 'b', 'a'], 'a')); // 4