On this page
  1. Array.reduce
  2. Signature & Overview
  3. Notes & Pitfalls
  4. Example

Array.reduce

Prev: filter | Up: Array | Next: find
Rel: Array, Array & Typed Arrays Guide
Ref: MDN Web Docs — Array.reduce
Tags: #public #web #javascript #builtins #array #tier/core


Signature & Overview

arr.reduce(fn(acc, cur, idx, arr), initialValue)

Reduces array elements left-to-right into a single accumulated value.

Notes & Pitfalls

Example

const nums = [10, 20, 30];
const total = nums.reduce((acc, n) => acc + n, 0);
console.assert(total === 60);

Linked from

Related notes