Skip to content

Instantly share code, notes, and snippets.

@avishwakarma
Created June 28, 2016 06:39
Show Gist options
  • Save avishwakarma/68ad93336e968791c7497c532f0fd214 to your computer and use it in GitHub Desktop.
Save avishwakarma/68ad93336e968791c7497c532f0fd214 to your computer and use it in GitHub Desktop.
JavaScript object size
/**
* size - Object size in javascript
* @uses {a:1, b:2}.size() // 2
*/
Object.prototype.size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment