lastIndexOf (object, startAt) Number
public
Returns the index of the given object's last occurrence. If no startAt
argument is given, the search starts from the last position. If it's negative, will count backward from the end of the array. Returns -1 if no match is found.
let arr = ['a', 'b', 'c', 'd', 'a']; arr.lastIndexOf('a'); // 4 arr.lastIndexOf('z'); // -1 arr.lastIndexOf('a', 2); // 0 arr.lastIndexOf('a', -1); // 4 arr.lastIndexOf('b', 3); // 1 arr.lastIndexOf('a', 100); // 4
Parameters:
-
object
Object
- the item to search for
-
startAt
Number
- optional starting location to search, default 0
Returns:
-
Number
- index or -1 if not found
Please login to continue.