Skip to content

lastIndexOf

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

此方法与 _.indexOf 类似,不同之处在于它从右到左迭代 array 的元素。

¥This method is like _.indexOf except that it iterates over elements of array from right to left.

新增于

¥Since

0.1.0

参数

¥Arguments

  1. array (数组):要检查的数组。

    ¥array (Array): The array to inspect.

  2. value (*):要搜索的值。

    ¥value ()*: The value to search for.

  3. [fromIndex=array.length-1] (数值):要从中搜索的索引。

    ¥[fromIndex=array.length-1] (number): The index to search from.

返回

¥Returns

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

¥(number): Returns the index of the matched value, else -1.

示例

¥Example

js
_.lastIndexOf([1, 2, 1, 2], 2);
// => 3

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

Lodash v4.17 中文网 - 粤ICP备13048890号