Skip to content

Instantly share code, notes, and snippets.

@KCreate
Created January 11, 2016 07:28
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 KCreate/dab19f3a251b7e8dac78 to your computer and use it in GitHub Desktop.
Save KCreate/dab19f3a251b7e8dac78 to your computer and use it in GitHub Desktop.
Object map functions
/*
Iterate over an object
*/
Object.prototype.map = function(cb) {
Object.keys(this).map(function(item) {
if (this.hasOwnProperty(item)) {
this[item] = cb(item, this[item], this);
}
}.bind(this));
return this;
}
/*
Iterate over an object and return an array with the changed values
*/
Object.prototype.armap = function(cb) {
return Object.keys(this).map(function(item) {
if (this.hasOwnProperty(item)) {
return cb(item, this[item], this);
}
}.bind(this));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment