Skip to content

findLast

js
_.findLast(collection, [predicate=_.identity], [fromIndex=collection.length-1])

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

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

新增于

¥Since

2.0.0

参数

¥Arguments

  1. collection (数组|对象):要检查的集合。

    ¥collection (Array|Object): The collection to inspect.

  2. [predicate=_.identity] (函数):每次迭代调用的函数。

    ¥[predicate=_.identity] (Function): The function invoked per iteration.

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

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

返回

¥Returns

(*):返回匹配的元素,否则为 undefined

¥()*: Returns the matched element, else undefined.

示例

¥Example

js
_.findLast([1, 2, 3, 4], function(n) {
  return n % 2 == 1;
});
// => 3

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