.map js
Jump to turn (8)
- User
.map js
- Assistant
The .map() method in JavaScript creates a new array with the results of calling a provided function on every element in the original array.
The syntax for .map() method is as follows:
array.map(function(currentValue, index, array) { // return element or new value }, thisValue);
The first parameter is the callback function, which takes three arguments:
- currentValue: the current element being processed in the array
- index: the index of the current element
- array: the original array on which the map() method was called
The second parameter is optional and represents the value to use as when executing the callback function.