Skip to content

Instantly share code, notes, and snippets.

@alizbazar
Created March 3, 2016 10:21
Show Gist options
  • Save alizbazar/9278ad8661af8a8abdf9 to your computer and use it in GitHub Desktop.
Save alizbazar/9278ad8661af8a8abdf9 to your computer and use it in GitHub Desktop.
Iterate through object properties and output their types
var keys = {};
lo.forEach(OBJECT, (item) => {
lo.forEach(item, (value, key) => {
if (!keys[key]) {
keys[key] = {};
}
var type = typeof value;
// differentiate Array from Object
type = (type == "object") ? (value instanceof Array ? "array" : "object") : type;
// capitalize
type = type[0].toUpperCase() + type.slice(1);
keys[key][type] = true;
});
});
lo.forEach(keys, (bool, key) => {
keys[key] = Object.keys(bool).join(' | ');
console.log(key + ': ' + keys[key]);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment