Function
Identifies the type of array elements
The array or array-like object of elements to be searched.
The (ordered) array or array-like object of elements to locate within theArray.
OptionalfromIndex: number
The index to start searching backwards from (the position at which subset's first element may occur). If the provided index value is a negative number, it is taken as the offset from the end of theArray. Default: theArray's length - 1 (search from the end).
The last index within theArray at which subset fully matches (or matches theArray's available elements from that position), or -1 if no such position exists. Returns fromIndex (normalized to a valid index, or theArray's length) if subset is empty.
arrLastIndexOfSubset([1, 2, 3, 4, 5], [3, 4]); // 2
arrLastIndexOfSubset([1, 2, 3, 4, 5], [4, 3]); // -1
arrLastIndexOfSubset(["a", "b", "a", "b", "c"], ["a", "b"]); // 2 (the later occurrence)
arrLastIndexOfSubset([1, 2, 3], [3, 4, 5]); // 2 (matches the available "3")
arrLastIndexOfSubset([1, 2, 3], []); // 3
// Repeated values -- returns the later occurrence, unlike arrIndexOfSubset()
let haystack = ["at foo", "at bar", "at foo", "at bar", "at baz"];
arrLastIndexOfSubset(haystack, ["at foo", "at bar"]); // 2
The arrLastIndexOfSubset() method returns the last index within theArray at which subset matches contiguously, comparing elements using strict equality (the same method used by the === or triple-equals operator). It is the mirror of arrIndexOfSubset, searching backwards from fromIndex (or the end of theArray) towards the start.
As with arrIndexOfSubset, if theArray has fewer remaining elements than subset from a candidate position, the comparison is limited to just those available elements -- so a subset that "runs off the end" of theArray is still considered a match against its available prefix.