JavaScript Intermediate Live preview

Array methods: map, filter and reduce

Transform, select and total a list of quiz scores without a single for loop.

Updated 5 Oct 2026 13 lines 1 min read

What you will learn

  • Create a new array with map()
  • Keep only some items with filter()
  • Combine items into one value with reduce()

Run the preview: the console shows what each line produces.

script.js
Download
const scores = [45, 72, 88, 39, 91, 66];

// map: a new array, one result per item
const percentages = scores.map(score => score + '%');
console.log('As percentages:', percentages);

// filter: only the items that pass a test
const passed = scores.filter(score => score >= 50);
console.log('Passed (50 and above):', passed);

// reduce: combine everything into one value
const total = scores.reduce((sum, score) => sum + score, 0);
console.log('Average score:', (total / scores.length).toFixed(1));
Not running
Run the preview when you are readyIt runs in an isolated sandbox with no access to this site or your account.
Make it your ownOpen the HTML, CSS and JavaScript in the Playground, change anything, and see the result instantly.
Edit in Playground
Hi there! đź‘‹ Have a question about the courses or joining the class? Ask me.