Get Object Size in JS


/ Published in: JavaScript
Save to your folder(s)

Function to validate the existence of each key in the object to get the number of valid key/value pairs.


Copy this code and paste it in your HTML
  1. /* Get Object Size */
  2. function objectSize(the_object){
  3. /* function to validate the existence of each key in the object to get the number of valid keys. */
  4. var object_size = 0;
  5. for (key in the_object){
  6. if (the_object.hasOwnProperty(key)){
  7. object_size++;
  8. }
  9. }
  10. return object_size;
  11. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.