array.map(function(currentValue, index, arr), thisValue)
Parameters: This method accepts two parameters as mentioned above and described below:
- function(currentValue, index, arr): It is required parameter and it runs on each element of array. It contains three parameters which are listed below:
- currentValue: It is required parameter and it holds the value of current element.
- index: It is optional parameter and it holds the index of current element.
- arr: It is optional parameter and it holds the array.
- thisValue: It is optional parameter and used to hold the value of passed to the function.
Return Value: It returns a new array and elements of arrays are result of callback function.
Example 1: This example use array map() method and return the square of array element.
Example 2: This example use array map() method to concatenate character ‘A’ with every character of name.
Example 3: This example use array map() method to return the square of array elements.
36, 49, 16, 25