Created
July 13, 2013 18:53
-
-
Save radist2s/5991791 to your computer and use it in GitHub Desktop.
Length of Javascript Object
This file contains 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
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