Created
March 29, 2019 23:19
-
-
Save jalbertbowden/4e0b0c4b151fdabbd158253db60115f4 to your computer and use it in GitHub Desktop.
Get object length by checking the key
This file contains hidden or 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
// http://stackoverflow.com/a/18560314 | |
// if condition is for old IE | |
if (!Object.keys) { | |
Object.keys = function (obj) { | |
var arr = [], | |
key; | |
for (key in obj) { | |
if (obj.hasOwnProperty(key)) { | |
arr.push(key); | |
} | |
} | |
return arr; | |
}; | |
} | |
Object.keys(obj).length; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment