DEV Community

Deepa Chaurasia
Deepa Chaurasia

Posted on

Javascript Map

The array.Map() allows you to iterate over array using loop.

This method allows you to iterate and modify it's elements using a callback function.

The callback function will then be executed on each of array's element.

Let's see with example:

Image description

Now imagine you have to multiply each element of array by 3.

Generally you use for loop like this:

Image description

By using map it will look like this:

Image description

How to use Map over Arrays of Object

Image description

You can iterate as follow

Image description

The Complete map() method syntax

The syntax of map() as follows
Image description

The function() is called on each array element, and the map() method always passes the current element,the index of current element and whole array object to it.

The this arguement will be used inside callback function.
By default it's value is undefined.

Image description

*Here you can see this value is 80 which is default value *

Thanks for reading,I hope you have learnt something new
Please like share and comment if it's useful for you guys.

Top comments (0)