JavaScript Array Map Method

The JavaScript method allows 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.

Reading Time: < 1 minute

In this short snippet tutorial, we’ll go over the JavaScript array map method, and see its basic use cases by using different examples.

This method can also be used to map() over an array of objects. See the example below.

The Complete Map() method syntax,index,array){ .... }, this);

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

The this argument will be used inside the callback function. By default, its value is undefined.

For example, here’s how we can change value of this to number 10;