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-