Last active
June 11, 2021 21:51
-
-
Save Rabios/97a059ec18f6dee477dee7fe061901e8 to your computer and use it in GitHub Desktop.
Returns size (length) of any type if possible
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
function sizeof(o) { | |
if (typeof(o) == "object") { | |
if (o.length !== void 0) { | |
return o.length; | |
} else { | |
var i = 0; | |
for (var k in o) i++; | |
return i; | |
} | |
} else if (typeof(o) == "string") { | |
return o.length; | |
} else { | |
return 1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment