Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Array.prototype.reduceRight: reducing from the end

reduceRight combines existing elements into one value while visiting indexes from right to left.

Version: ECMAScript 2026 draft; example target: Node.js 24.22.2

Syntax

array.reduceRight(callbackFn[, initialValue])

array.reduceRight(callbackFn[, initialValue]) calls callbackFn(accumulator, currentValue, index, array) for existing indexes in descending order and returns the final accumulator. With initialValue it starts there. Without it, the last existing element becomes the accumulator and is not passed as currentValue.

Sparse holes are skipped. An empty or all-hole array without initialValue throws TypeError; explicit undefined counts as a supplied start. Length is captured before iteration, so an append beyond it is ignored and an index deleted before its visit is skipped. The method itself does not mutate and is generic for array-like values; a non-callable callback, null or undefined receiver, and callback failures throw.

Examples

const sparse = [1, , 3, 4];
const steps = [];
const total = sparse.reduceRight((accumulator, value, index) => {
  steps.push(index + ":" + accumulator + "-" + value);
  return accumulator - value;
}, 20);
console.log(total);
console.log(steps.join("|"));
console.log([, 5, ,].reduceRight((a, b) => a + b));
try { new Array(2).reduceRight((a, b) => a + b); } catch (error) { console.log(error.name); }

Result

12
3:20-4|2:16-3|0:13-1
5
TypeError

Sources