Skip to content

Instantly share code, notes, and snippets.

@esundahl
Created February 21, 2012 22:09
Show Gist options
  • Save esundahl/1879346 to your computer and use it in GitHub Desktop.
Save esundahl/1879346 to your computer and use it in GitHub Desktop.
Javascript: get an array of all property names in an object
keys : function (o) {
var accumulator = [];
for (var propertyName in o) {
accumulator.push(propertyName);
}
return accumulator;
}
//get values instead of keys
values : function (o) {
var accumulator = [];
for (var propertyName in o) {
accumulator.push(o[propertyName]);
}
return accumulator;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment