Skip to content

Instantly share code, notes, and snippets.

@akabab
Created April 2, 2018 10:39
Show Gist options
  • Save akabab/6c8be6a833657c1b0259c74f3f015f72 to your computer and use it in GitHub Desktop.
Save akabab/6c8be6a833657c1b0259c74f3f015f72 to your computer and use it in GitHub Desktop.
const flatKeys = (object, keys = [], k = '') => {
for (const key in object) {
const rest = k.length ? '.' + key : key
if (typeof object[key] === 'object' && !Array.isArray(object[key])) {
flatKeys(object[key], keys, k + rest)
} else {
keys.push(k + rest)
}
}
return keys
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment