当前位置: 首页 > 文档资料 > Lazy.js 英文文档 >

lastIndexOf

优质
小牛编辑
132浏览
2023-12-01

Performs (at worst) a linear search from the tail of this sequence, returning the last index at which the specified value is found.

Signature

Sequence.lastIndexOf = function(value) { /*...*/ }
Sequence.lastIndexOf = function lastIndexOf(value, equalityFn) {
  var reversed = this.getIndex().reverse(),
  index    = reversed.indexOf(value, equalityFn);
  if (index !== -1) {
index = reversed.length() - index - 1;
  }
  return index;
}
NameType(s)Description
value*

The element to search for in the sequence.

returnsnumber

The last index within this sequence where the given value is located, or -1 if the sequence doesn't contain the value.

Examples

Lazy(["a", "b", "c", "b", "a"]).lastIndexOf("b")    // => 3
Lazy([1, 2, 3]).lastIndexOf(0)                      // => -1
Lazy([2, 2, 1, 2, 4]).filter(isEven).lastIndexOf(2) // 2