Lodash _.lastIndexOf

2021-09-24 09:41 更新

_.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


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号