Skip to content

Instantly share code, notes, and snippets.

@stevegraham
Created May 21, 2011 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevegraham/984829 to your computer and use it in GitHub Desktop.
Save stevegraham/984829 to your computer and use it in GitHub Desktop.
JavaScript Array#map
Array.prototype.map = function(func) {
var output = []
for(i=0; i < this.length; i++) {
output[i] = func(this[i])
}
return output
}
// Example usage:
// [1,2,3].map(function(i) { return i * i })
// returns [1, 4, 9]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment