Created
March 3, 2016 10:21
-
-
Save alizbazar/9278ad8661af8a8abdf9 to your computer and use it in GitHub Desktop.
Iterate through object properties and output their types
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
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