Example 1 — Official Samples
Find the last 3, then look for a value that isn’t there.
console.log(R.lastIndexOf(3, [-1, 3, 3, 0, 1, 2, 3, 4])); // 6
console.log(R.lastIndexOf(10, [1, 2, 3, 4])); // -1 How It Works
- Start at the end. The search begins at index
7(the value4). - First hit wins. Index
6holds3, so the answer is6— the 3s at indexes 1 and 2 are ignored. - Not found.
10is not in[1, 2, 3, 4], so the walk reaches the start and returns-1. - Zero-based. Like every array index, counting starts at
0.
