Created
January 11, 2016 07:28
-
-
Save KCreate/dab19f3a251b7e8dac78 to your computer and use it in GitHub Desktop.
Object map functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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