Skip to content

Instantly share code, notes, and snippets.

@TheNeuralBit
Created April 20, 2016 18:12
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 TheNeuralBit/4f2c7705ccb818a2b8c32e7095f5bca4 to your computer and use it in GitHub Desktop.
Save TheNeuralBit/4f2c7705ccb818a2b8c32e7095f5bca4 to your computer and use it in GitHub Desktop.
Convenience function for iterating through keys and values of a JS Object
// obj.forEach(function(k, v) { ... });
Object.prototype.forEach = function forEach(callback) {
for (var key in this) {
if (this.hasOwnProperty(key)) {
callback(key, this[key]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment