阅读(1127) (0)

Lodash _.lastIndexOf

2021-09-17 17:24:30 更新

_.lastIndexOf(array, value, [fromIndex=array.length-1])

这个方法类似_.indexOf ,区别是它是从右到左遍历array的元素。

引入版本

0.1.0

参数

  1. array (Array): 要搜索的数组。
  2. value (*): 要搜索的值。
  3. [fromIndex=array.length-1] (number): 开始搜索的索引值。

返回值

(number): 返回匹配值的索引值,否则返回 -1。

例子

_.lastIndexOf([1, 2, 1, 2], 2);
// => 3
 // Search from the `fromIndex`.
_.lastIndexOf([1, 2, 1, 2], 2, 2);
// => 1