MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
map, filter, reduce0%
Study Materials
JavaScript for IntermediateProgress 0%
1.1Block Scope with let & const1.2Template Literals1.3Destructuring Arrays and Objects1.4Default Parameters1.5Enhanced Object Literals
5.1map, filter, reduce5.2find, some, every5.3Array.from & Array.of5.4Deep Copy vs Shallow Copy
HomeTutorialsJavaScript for Intermediatemap, filter, reduce
find, some, every

map, filter, reduce

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

Functional array processing is one of the most transformative paradigms in modern JavaScript. Rather than writing imperative for loops with mutating variables, map, filter, and reduce express data transformations declaratively, producing cleaner, bug-free, and highly testable code.


1. Array.prototype.map()

map() creates a new array populated with the results of calling a provided function on every element in the calling array. It never mutates the original array and always maintains a 1:1 length ratio.

1Input Array: [ 10, 20, 30 ]
2Transformation: (x * 2)
3Output Array: [ 20, 40, 60 ]

2. Array.prototype.filter()

filter() creates a shallow copy of a portion of a given array, filtered down to just the elements that pass the test implemented by the provided callback function (evaluates to truthy).

1Input Array: [ 120, 85, 450 ]
2Predicate: (price < 100)
3Output Array: [ 85 ]

3. Array.prototype.reduce()

reduce() executes a user-supplied "reducer" callback function on each element of the array, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements is a single value (number, string, object, or aggregated array).

1Syntax: array.reduce((accumulator, currentValue, currentIndex, array) => { ... }, initialValue)

Computing Aggregates (Sum)

1const totalCompletedRevenue = completedTx.reduce((acc, tx) => acc + tx.amount, 0);
2console.log(`Total Revenue: $${totalCompletedRevenue}`);

Grouping Data with reduce()

1const inventory = [
2 { name: 'Apples', category: 'Fruit' },
3 { name: 'Carrots', category: 'Vegetable' },
4 { name: 'Bananas', category: 'Fruit' },
5 { name: 'Broccoli', category: 'Vegetable' }
6];
7 
8const groupedByCategory = inventory.reduce((acc, item) => {
9 const cat = item.category;
10 if (!acc[cat]) {
11 acc[cat] = [];
12 }
13 acc[cat].push(item.name);
14 return acc;
15}, {});
16 
17console.log(groupedByCategory);
18// {
19// Fruit: ['Apples', 'Bananas'],
20// Vegetable: ['Carrots', 'Broccoli']
21// }

4. Method Chaining: The Declarative Pipeline

Because map and filter return new arrays, you can chain them into functional data pipelines:

1const orders = [
2 { customer: 'Alice', items: 3, total: 150, refunded: false },
3 { customer: 'Bob', items: 1, total: 40, refunded: true },
4 { customer: 'Charlie', items: 5, total: 320, refunded: false }
5];
6 
7const averageValidOrderSize = orders
8 .filter(order => !order.refunded)
9 .map(order => order.total)
10 .reduce((sum, total, _, arr) => sum + (total / arr.length), 0);
11 
12console.log(`Average Order: $${averageValidOrderSize.toFixed(2)}`);

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What will Array.prototype.map() return if the original array has 5 elements?
Question 2
What happens if you omit the initialValue parameter in Array.prototype.reduce()?
Question 3
Which method should you choose to remove invalid or falsy elements from an array?
Question 4
What does the code [1, 2, 3, 4].filter(x => x % 2 === 0).map(x => x * 10) return?
Question 5
Can reduce() return a complex object or array instead of a primitive number?
Next Lesson

find, some, every

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Form Events and Validationfind, some, every

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Intermediate with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext