JavaScript Map Function ❗❗❗

Sometimes you may need to take an array and apply some procedure to its elements so that you get a new array with modified elements. Instead of manually iterating over the array using a loop, you can simply use the built-in method. The method allows you to iterate over an array and modify its elements using a callback function. The callback function will then be executed on each of the array's elements.

For example, suppose you have the following array doing some basic operation over the elements.

Iterate over an array using for loop

But you can actually use the method to achieve the same result. Here's an example:

Iterate over an array using map() method

The method is commonly used to apply some changes to the elements, whether multiplying by a specific number as in the code above, or doing any other operations that you might require for your application.

Thanks a lot for reading till end. You can contact me in case if you need any help.👍👍👍👍👍👍

All Links:



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store