E2EHIRING Logo
search

Search blogs by title

Jobs
Jobs
internships
Internships
Company
Partners
mentorship
Mentorship
more
Moredropdown
Login
HomeSepratorIconBlogsSepratorIconJAVASCRIPT ARRAY METHODS (MAP, FILTER AND REDUCE FUNCTIONS)SepratorIcon

JAVASCRIPT ARRAY METHODS (MAP, FILTER AND REDUCE FUNCTIONS)

Han SoloAnbarasan Murugan
calendar27 Jun 2022
poster

MAP:


The map() method is used for creating a new array from an existing one, applying a function to each one of the elements of the first array.

Example;

const numbers=[1,2,3,4,5]
const results=numbers.map((x)=>{
return x;
});
console.log(results) ;//output [1,2,3,4,5]

FILTER:

The filter() method takes each element in an array and it applies a conditional statement against it. If this conditional returns true, the element gets pushed to the output array. If the condition returns false, the element does not get pushed to the output array.

Example;

const arr=[22,11,3,4,6]
const evens=arr.filter((x)=>{
return x%2===0;
});
 console.log(evens);//output even number[22,4,6]

REDUCE:

The reduce() method reduces an array of values down to just one value. To get the output value, it runs a reducer function on each element of the array.

 Example;

const numbers=[1,2,3,4]
const sum=numbers.reduce((result,item)=>{
return result+item;

},0);
console.log(sum);//output(10)

Recent Posts

Innovation is the Need of the Hour: Else you are Outdated

Innovation is the Need of the Hour: Else you are Outdated

Router In React

Router In React

Higher Order Component in React

Higher Order Component in React

Styled Component in React

Styled Component in React

Spring - Bean Life Cycle

Spring - Bean Life Cycle

copycopycopycopy

Han Solo

Recent Posts

Innovation is the Need of the Hour: Else you are Outdated

Innovation is the Need of the Hour: Else you are Outdated

Router In React

Router In React

Higher Order Component in React

Higher Order Component in React

Styled Component in React

Styled Component in React

Spring - Bean Life Cycle

Spring - Bean Life Cycle

e2e logo