Last active
August 20, 2020 20:56
-
-
Save lunule/6f37520c90f9175c9c42201dd31ca893 to your computer and use it in GitHub Desktop.
[JavaScript - Get Object Size] #javascript #js #object #array #size #length
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
/** | |
* Get Object Size | |
* ---------------- | |
* Function to validate the existence of each key in the object to get the number of valid keys. | |
* | |
* @see https://css-tricks.com/snippets/javascript/get-object-size/ | |
*/ | |
function objectSize(the_object) { | |
var object_size = 0; | |
for ( key in the_object ) { | |
if ( the_object.hasOwnProperty(key) ) | |
object_size++; | |
}; | |
return object_size; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment