JavaScript Array map() Method
Example
Return an array with the square root of all the values in the original array:
var numbers = [4, 9, 16, 25];
function myFunction() {
x = document.getElementById("demo")
x.innerHTML = numbers.map(Math.sqrt);
}
The result will be:
2,3,4,5
Definition and Usage
The map() method creates a new array with the results of calling a function for every array element.
The map() method calls the provided function once for each element in an array, in order.
Note: map() does not execute the function for array elements without values.
Note: map() does not change the original array.
0 Comments
If you have any doubts,please let me know