Skip to content

Instantly share code, notes, and snippets.

@danielronnkvist
Created May 30, 2016 08:09
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 danielronnkvist/aba9103e44770b4e2298c039662b7b29 to your computer and use it in GitHub Desktop.
Save danielronnkvist/aba9103e44770b4e2298c039662b7b29 to your computer and use it in GitHub Desktop.
Simple map function for JS objects.
/*
Use like
{key: "value"}.map((object, key) => { console.log(key) })
*/
if (typeof Object.prototype.map != 'function') {
Object.prototype.map = function(callback) {
'use strict';
if (this == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var target = Object(this);
return Object.keys(target).map(callback.bind(this, target));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment