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
arr.map(function(element,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;