Skip to content

Instantly share code, notes, and snippets.

@streunerlein
Created August 17, 2012 11:05
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 streunerlein/3378008 to your computer and use it in GitHub Desktop.
Save streunerlein/3378008 to your computer and use it in GitHub Desktop.
Array.map() that works with undefined values in Array
Array.prototype.ownMap = function(fn) { var a = new Array(this.length); for (var i = 0; i < this.length; i++) a[i] = fn(this[i]); return a; }
// t = new Array(4)
// > [undefined × 4]
// t.ownMap(function(d) { return "Q"; })
// > ["Q", "Q", "Q", "Q"]
// t
// > [undefined × 4]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment