Lodash - forEachRight 方法
語法
_.forEachRight(collection, [iteratee=_.identity])
此方法類似於 _.forEach,只是它從右到左遍歷集合中的元素。
引數
collection (陣列或物件) − 要遍歷的集合。
[iteratee=_.identity] (函式) − 每次迭代呼叫的函式。
輸出
(*) − 返回集合。
示例
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.htm
廣告