Posted By

aurorius on 11/04/10


Tagged

javascript


Versions (?)

Count Object Keys


 / Published in: JavaScript
 

  1. Object.prototype.count = function()
  2. {
  3. c = 0;for(i in this){if (this.hasOwnProperty(i)){c++;}};return c;
  4. }
  5.  
  6. MyObject = {
  7. a : '0',
  8. b : '1',
  9. c : '2'
  10. }
  11.  
  12. alert(MyObject.count())

Report this snippet  

You need to login to post a comment.