Skip to content

Instantly share code, notes, and snippets.

@radist2s
Created July 13, 2013 18:53
Show Gist options
  • Save radist2s/5991791 to your computer and use it in GitHub Desktop.
Save radist2s/5991791 to your computer and use it in GitHub Desktop.
Length of Javascript Object
Object.size = function(obj) {
if (obj.hasOwnProperty){
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
}
else {
return Object.keys(obj).length
}
};
// Get the size of an object
var size = Object.size(myObj);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment