JavaScript Iterate over Arrays with map

J

The map method is a convenient way to iterate through arrays.
The map method will iterate through every element of the array and create a new array with values that have been modified by the callback function, and return it.

Here’s an example usage:

var oldArray = [1, 2, 3];
var timesFour = oldArray.map(function(val){
    return val * 4;
});
console.log(timesFour); // returns [4, 8, 12]
console.log(oldArray);  // returns [1, 2, 3]

#Note that it does not modify the original array.

About the author

Imran Pollob

Learn => Practice => Implement => Repeat

Add comment

Categories

Imran Pollob

Learn => Practice => Implement => Repeat

Get in touch