Lesson 16 — Array reduce
Fold many values into one
reduce(fn, start) walks the array and carries an accumulator — the result so far. For each item it calls fn(acc, item) and the return value becomes the new acc. The second argument is the starting value; for sums use 0.
[10, 25].reduce((acc, p) => acc + p, 0); // 0 → 10 → 35
You can also find the biggest value: return whichever of acc and p is larger.
Why it matters: totals, maximums and averages are all one reduce away.
Total the prices with reduce, and find the most expensive price with a second reduce.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based JavaScript Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for JavaScript Foundations books — check the publication year so the examples match current versions.
Search Amazon →