Created
February 21, 2012 22:09
-
-
Save esundahl/1879346 to your computer and use it in GitHub Desktop.
Javascript: get an array of all property names in an object
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
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