JS Performance
Measure the slow part before changing it. Repeated work inside a loop is often easier to remove than a whole algorithm is to replace.
Where to run this
This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.
A practical example
const prices = [2, 4, 6];
let total = 0;
for (const price of prices) total += price;
console.log(total);
What happens
A single pass calculates the total 12.