Posted By

reverend on 03/02/12


Tagged

javascript object size counter


Versions (?)

Get Object Size in JS


 / Published in: JavaScript
 

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

  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  

You need to login to post a comment.