Lodash - forEachRight 方法

语法

_.forEachRight(collection, [iteratee=_.identity])

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

参数

  • collection (Array|Object) − 要迭代的集合。

  • [iteratee=_.identity] (Function) − 每次迭代调用的函数。

输出

  • (*) −返回集合。

示例

var _ = require('lodash');
var list = [1 , 2, 3, 4, 5];

_.forEachRight(list, function(value) {
    console.log(value);
});

将上述程序保存在 tester.js 中。运行以下命令执行此程序。

命令

\>node tester.js

输出

5
4
3
2
1

lodash_collection.html