.map() Method
The .map()
method is an easy way to update all the elements in your array based on a single function. In this example we'll triple every number in our array.
var nums = [1, 2, 3, 4, 5];
var numsTrip = nums.map(function(element) {
return element * 3;
});
console.log(numsTrip);
Output
[ 3, 6, 9, 12, 15 ]
Last updated