Lodash教程

Lodash reduceRight method

语法:

_.reduceRight(collection, [iteratee=_.identity], [accumulator])
This method is like _.reduce except that it iterates over elements of collection from right to left.

参数:

collection (Array|Object) − The collection to iterate over. [iteratee=_.identity] (Function) − The function invoked per iteration. [accumulator] (*) − The initial value.

输出:

(*) − Returns the accumulated value.

例子:

var _ = require('lodash');
var list = [[0, 1], [2, 3], [4, 5]];
var result = _.reduceRight(list, function(flattened, other) {
   return flattened.concat(other);
}, []);
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

命令:

\>node tester.js

输出:

[ 4, 5, 2, 3, 0, 1 ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4