innovationM
← Back to Blogs

JavaScript

Map Method  IN Javascript

InnovationM Admin 10 Nov 2022 2 min read
Map Method  IN Javascript

The map method holds key and value pair, the key can be any datatype.

The map method is the function for every array element and returns the new part. The map method does not change the original array.

We can create a map method passing an Array to a new Map().

We can set the value  Map.set().

Syntax-

-array.map(callback(currentval,index,arr),thisArg

-Callback- This represents the function that produces the new array .

Currentval-  This shows the current element of an array.

Index-  This shows the index of the current element.

Arr- it is optional.

Above code, we can get the whole array without changing the original array.

In the second image, we can get only the company name by using company.name.

 

New Map()-

We can create a Map by passing an Array to the new Map() constructor:

By new map() we are able to create a new array.

output-

Map.set()-

We can add elements to a map with the set method. Set methods are also used to change the old values.

output-

Map.get()-

It is used to get the value of a key in a map method.a map object remembers the original insertion order of the keys.

output-

About the Author

InnovationM Admin

Contributor at InnovationM.

LinkedIn

Transform Your Ideas with Expert Guidance

icon
15+ Years of Expertise

Delivering high-impact solutions with years of industry experience.

icon
100+ Satisfied Clients

Helping contact industry software experts to achieve their brand goals.

icon
250+ In-House Team Members

A skilled team ready to tackle projects of any scale.

Book a consultation call with our experts today