Lodash _.indexOf

2021-09-22 09:38 更新

_.indexOf(array, value, [fromIndex=0])

使用SameValueZero 等值比较,返回首次 value 在数组array中被找到的 索引值, 如果 fromIndex 为负值,将从数组array尾端索引进行匹配。

引入版本

0.1.0

参数

  1. array (Array): 需要查找的数组。
  2. value (*): 需要查找的值。
  3. [fromIndex=0] (number): 开始查询的位置。

返回值

(number): 返回 值value在数组中的索引位置, 没有找到为返回-1。

例子

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


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

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号