Skip to content

Instantly share code, notes, and snippets.

@psycalc
Created June 20, 2016 14:28
Show Gist options
  • Save psycalc/8c1d04af446af3abcbd8d363dc57e655 to your computer and use it in GitHub Desktop.
Save psycalc/8c1d04af446af3abcbd8d363dc57e655 to your computer and use it in GitHub Desktop.
The map method is a convenient way to iterate through arrays.
//The map method is a convenient way to iterate through arrays. Here's an example usage:
var timesFour = oldArray.map(function(val){
return val * 4;
});
//The map method will iterate through every element of the array, creating a new array with values that have been modified by the callback function, and return it. Note that it does not modify the original array.
//In our example the callback only uses the value of the array element (the val argument) but your callback can also include arguments for the index and array being acted on.
//Use the map function to add 3 to every value in the variable oldArray, and save the results into variable newArray. oldArray should not change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment