Count Object Keys


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



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.