Lodash findLast method
语法:
_.findLast(collection, [predicate=_.identity], [fromIndex=collection.length-1])
This method is like _.find except that it iterates over elements of collection from right to left.
参数:
collection (Array|Object) − The collection to iterate over.
[iteratee=_.identity] (Function) − The iteratee to transform keys.
输出:
(Object) − Returns the composed aggregate object.
例子:
var _ = require('lodash');
var list = [1 , 2, 3, 4, 5]
var result = _.findLast(list, function(n) {
return n % 2 == 1;
});
console.log(result);
Save the above program in
tester.js. Run the following command to execute this program.
命令:
输出: