Skip to content

Instantly share code, notes, and snippets.

@davodey
Last active January 24, 2017 22:04
Show Gist options
  • Save davodey/d1e8656e5d487f2dfde1fd55b3d290bd to your computer and use it in GitHub Desktop.
Save davodey/d1e8656e5d487f2dfde1fd55b3d290bd to your computer and use it in GitHub Desktop.
Example using the ES6 map helper.
var numbers = [1,2,3];
var doubledNumbers = [];
// want to move away from this
for (var i = 0; i < numbers.length; i++) {
doubledNumbers.push(numbers[i] * 2);
}
// creates a new array with values returned from function
var doubled = numbers.map(function(number){
return number * 2
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment