Skip to content

Instantly share code, notes, and snippets.

@jalbertbowden
Created March 29, 2019 23:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jalbertbowden/4e0b0c4b151fdabbd158253db60115f4 to your computer and use it in GitHub Desktop.
Save jalbertbowden/4e0b0c4b151fdabbd158253db60115f4 to your computer and use it in GitHub Desktop.
Get object length by checking the key
// 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