_.findLastIndex(查找元素的索引值)
语法:
_.findLastIndex(array, [predicate=_.identity], [fromIndex=array.length-1])源代码链接:source
npm包链接:npm package
描述:
这个方法类似于_.findIndex。除了它从右到左遍历集合的元素。
开始版本:2.0.0
参数:
array (Array): 需要检索的数组。[predicate=_.identity] (Function): 每个迭代函数调用。[fromIndex=array.length-1] (number): 开始搜索的索引值。
返回值:
(number): 返回查找到的元素索引值,否则f返回-1。
例子:
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false },
{ 'user': 'pebbles', 'active': false }
];
_.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
// => 2
// The `_.matches` iteratee shorthand.
_.findLastIndex(users, { 'user': 'barney', 'active': true });
// => 0
// The `_.matchesProperty` iteratee shorthand.
_.findLastIndex(users, ['active', false]);
// => 2
// The `_.property` iteratee shorthand.
_.findLastIndex(users, 'active');
// => 0注意:不同的方式代表:_.matches,_.matchesProperty,_.property的简写法
Last updated
Was this helpful?