Created
June 28, 2016 06:39
-
-
Save avishwakarma/68ad93336e968791c7497c532f0fd214 to your computer and use it in GitHub Desktop.
JavaScript object size
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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