Skip to content

Instantly share code, notes, and snippets.

@lunule
Last active August 20, 2020 20:56
Show Gist options
  • Save lunule/6f37520c90f9175c9c42201dd31ca893 to your computer and use it in GitHub Desktop.
Save lunule/6f37520c90f9175c9c42201dd31ca893 to your computer and use it in GitHub Desktop.
[JavaScript - Get Object Size] #javascript #js #object #array #size #length
/**
* 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