javascript: get length of an object's children


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

if you need ecmascript 5 functions then use underscore.js


Copy this code and paste it in your HTML
  1. Object.prototype.size = function() {
  2. var size = 0, key;
  3. for (key in this) {
  4. if (this.hasOwnProperty(key)) size++;
  5. }
  6. return size;
  7. };

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.