Monday, 4 Aug 2025
  • My Interests
  • My Saves
  • Try Intents
Subscribe
Focus - Code Reveals
  • Home
  • HTML

    What is Block level Element and Inline Level Element?

    By Chief Editor

    Difference between HTML Tag and HTML Element in HTML?

    By Chief Editor

    What is the difference between “HTML” and “HTML5”?

    By Chief Editor

    What is Doctype HTML in HTML?

    By Chief Editor
    What is Symentic HTML

    What is Symentic HTML?

    By Chief Editor

    What is a Meta Tag in HTML?

    By Chief Editor
  • JavaScript

    What is a Promise in JavaScript, and what are its parameters?

    By Chief Editor

    What is hoisting in JavaScript with an example?

    By Chief Editor

    What is a Closure in JavaScript?

    By Chief Editor

    Is JavaScript a synchronous or asynchronous language?

    By Chief Editor

    What is memoization in JavaScript?

    By Chief Editor

    What is the Event Loop in JavaScript?

    By Chief Editor
  • Frontend Interview

    What is Block level Element and Inline Level Element?

    By Chief Editor

    Explain Deep Copy and Shallow Copy in JavaScript.

    By Chief Editor

    How to Reverse a String in JavaScript: Two Essential Methods

    By Chief Editor

    What is Symentic HTML?

    By Chief Editor

    What is Position in CSS?

    By Chief Editor

    What are the Lexical Scope in JavaScript?

    By Chief Editor
  • Backend Interview

    What is a Promise in JavaScript, and what are its parameters?

    By Chief Editor

    Explain the useState and useEffect hooks in React

    By Chief Editor

    What is a Closure in JavaScript?

    By Chief Editor

    What is props drilling in React?

    By Chief Editor

    How Can You Share Data Between Components in React?

    By Chief Editor

    What are Benefits in React?

    By Chief Editor
  • Nodejs
  • JavaScript Interview
  • React Interview
  • Frontend Interview
  • Backend Interview
  • Contact Us
  • Advertise with Us
  • Complaint
  • Cookies Policy
  • Privacy Policy
  • Donate
  • 🔥
  • ReactJS
  • JavaScript
  • JavaScript Interview
  • React Interview
  • HTML
  • Frontend Interview
  • CSS
  • Redux
  • Javascript
  • System Design
Font ResizerAa
Focus - Code RevealsFocus - Code Reveals
  • My Saves
  • My Interests
  • My Feed
  • History
  • Technology
Search
  • Homepage
  • ReactJS
  • JavaScript
  • JavaScript Interview
  • HTML
  • CSS
  • Backend Interview
Have an existing account? Sign In
Follow US
© 2022 Code Reveals Inc. All Rights Reserved.
Home Blog What are the map, filter, and reduce methods in JavaScript?
JavaScriptJavaScript Interview

What are the map, filter, and reduce methods in JavaScript?

Chief Editor
Last updated: February 16, 2025 1:35 pm
Chief Editor
Share
SHARE

In JavaScript, map(), filter(), and reduce() are array methods that help in transforming and processing data efficiently. They are part of the functional programming paradigm and are commonly used in modern JavaScript development.

Contents
1. map() Method2. filter() Method3. reduce() MethodComparison Summary:

1. map() Method

The map() method creates a new array by applying a function to each element of an existing array.

Syntax:

javascriptCopyEditconst newArray = array.map((element, index, array) => {
  // Return the modified element
});

Key Points:

  • Returns a new array with the results of applying the function to every element.
  • Does not modify the original array.

Example:

javascriptCopyEditconst numbers = [1, 2, 3, 4];
const squared = numbers.map(num => num * num);
console.log(squared); // [1, 4, 9, 16]

2. filter() Method

The filter() method creates a new array containing only the elements that satisfy a given condition.

Syntax:

javascriptCopyEditconst filteredArray = array.filter((element, index, array) => {
  // Return true to keep the element, false to discard it
});

Key Points:

  • Returns a new array with elements that pass the test.
  • Does not modify the original array.

Example:

javascriptCopyEditconst numbers = [1, 2, 3, 4, 5];
const evenNumbers = numbers.filter(num => num % 2 === 0);
console.log(evenNumbers); // [2, 4]

3. reduce() Method

The reduce() method reduces the array to a single value by executing a reducer function.

Syntax:

javascriptCopyEditconst result = array.reduce((accumulator, currentValue, index, array) => {
  // Return updated accumulator
}, initialValue);

Parameters:

  • accumulator – Accumulates the result.
  • currentValue – Current element being processed.
  • initialValue – Optional initial value of the accumulator.

Key Points:

  • Returns a single value.
  • Useful for calculations like summing elements, flattening arrays, etc.

Example:

javascriptCopyEditconst numbers = [1, 2, 3, 4];
const sum = numbers.reduce((acc, curr) => acc + curr, 0);
console.log(sum); // 10

Comparison Summary:

MethodPurposeReturn ValueTypical Use Case
map()Transform each element in an array.New arrayTransform data (e.g., double each number).
filter()Filter elements based on a condition.New arrayGet a subset of elements (e.g., even numbers).
reduce()Reduce the array to a single value.Single valueAggregate data (e.g., sum, product).

These methods make working with arrays cleaner and more readable, especially when dealing with large data transformations.

Share This Article
Email Copy Link Print
Previous Article What is a Promise in JavaScript, and what are its parameters?
Next Article What is Scope in JavaScript?
Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Your Trusted Source for Accurate and Timely Updates!

Our commitment to accuracy, impartiality, and delivering breaking news as it happens has earned us the trust of a vast audience. Stay ahead with real-time updates on the latest events, trends.
FacebookLike
XFollow
InstagramFollow
YoutubeSubscribe
LinkedInFollow
QuoraFollow
- Advertisement -
Ad imageAd image

Popular Posts

What is state in React, and what are its properties?

State in React is a built-in object that is used to store and manage data…

By Chief Editor

What is a Closure in JavaScript?

A closure in JavaScript is a function that remembers the variables from its outer lexical…

By Chief Editor

What is props drilling in React?

Props Drilling is a situation in React where data (props) needs to be passed through…

By Chief Editor

You Might Also Like

JavaScriptJavaScript Interview

What is a Promise in JavaScript, and what are its parameters?

By Chief Editor
JavaScriptJavaScript Interview

What is the this Keyword in JavaScript?

By Chief Editor
JavaScript

Explain var let and const in JavaScript with Example.

By Chief Editor
Frontend InterviewJavaScript

Explain Deep Copy and Shallow Copy in JavaScript.

By Chief Editor

Focus by CodeReveals is your dedicated platform for mastering tech interviews and advancing your development skills. Whether you’re aiming to become a Frontend Developer, Backend Developer, or simply preparing for your next big interview, we’re here to guide you every step of the way.

Our mission is to help aspiring developers gain real-world knowledge, build confidence, and succeed in technical interviews. We offer structured content, curated interview questions, coding challenges, and practical guidance — all designed by experienced professionals who understand what top tech companies are looking for.

At Improve, we don’t just teach — we prepare you to think like a developer, solve like an engineer, and present like a pro.

Join us and start improving today — because your dream tech job is within reach

Most Famous
  • HTML
  • CSS
  • JavaScript
  • NodeJS
Top Categories
  • JavaScript Interview
  • React Interview
  • Frontend Interview
  • Backend Interview
Usefull Links
  • Contact Us
  • Advertise with Us
  • Complaint
  • Cookies Policy
  • Privacy Policy
  • Donate

©2025  Code Reveals Inc. All Rights Reserved.

Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?