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.

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More