Skip to content

Instantly share code, notes, and snippets.

@sente
Forked from Cside/object_keys_values.js
Created November 12, 2012 02:50
Show Gist options
  • Select an option

  • Save sente/4057240 to your computer and use it in GitHub Desktop.

Select an option

Save sente/4057240 to your computer and use it in GitHub Desktop.
Object.keys(), Object.values()
// changed the functions from .keys() -> ._keys(), likewise for .values()
// because .keys()/.values() breaks jQuery
Object.prototype._keys = function (i) {
var keys = Object.keys(this);
return (i >= 0) ? keys[i] : keys;
};
Object.prototype._values = function (i) {
var self = this;
var values = Object.keys(this).map(function(key){
return self[key];
});
return (i >= 0) ? values[i] : values;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment