๐Ÿ”— JavaScript

map, filter, reduce โ€” The JavaScript Methods That Get You Hired

๐Ÿ“… Jun 14, 2026 โฑ 5 min read

Interviewers use these three to separate copy-pasters from developers. Each answers a different question.

map โ€” transform every item

const prices = [100, 200, 300];
const withGst = prices.map(p => p * 1.18);   // [118, 236, 354]

filter โ€” keep some items

const students = [{name:"A", cgpa: 8.7}, {name:"B", cgpa: 6.2}];
const eligible = students.filter(s => s.cgpa >= 7);

reduce โ€” fold into one value

const total = [10, 20, 30].reduce((sum, n) => sum + n, 0);   // 60

// count occurrences โ€” classic interview task
const counts = "hello".split("").reduce((acc, ch) => {
  acc[ch] = (acc[ch] || 0) + 1;
  return acc;
}, {});   // {h:1, e:1, l:2, o:1}

Chained โ€” real-world shape

const revenue = orders
  .filter(o => o.status === "paid")
  .map(o => o.amount)
  .reduce((sum, n) => sum + n, 0);

Key property: none of them mutate the original array. Practice on the DSA judge โ€” several problems are one-liners with these.

โ† All Articles