The reduceRight
method in Javascript uses an accumulator and a value from an array in order to reduce the array.
Examples
Let’s reduce the nested array below into a single array:
const arry = [
[2, 4],
[6, 8],
[10, 12]
];
const reduceArray = arry.reduceRight((acc, curr) => acc.concat(curr));
console.log(reduceArray); //[10, 12, 6, 8, 2, 4];
reduceRight
starts at the last array ([10, 12]
) and works its way to the first array ([2, 4]
).