Skip to content

Instantly share code, notes, and snippets.

@RavenHursT
Created August 31, 2018 18:34
Show Gist options
  • Save RavenHursT/8f15064739b873302c4e6547d9f10426 to your computer and use it in GitHub Desktop.
Save RavenHursT/8f15064739b873302c4e6547d9f10426 to your computer and use it in GitHub Desktop.
function flatten(source, k, keyPath = [], result = {}) {
if(typeof source !== `object` || source === null) {
result[keyPath.join('.')] = source
return result
}
let iterationResult
for (k in source) {
keyPath.push(k)
iterationResult = flatten(source[k], k, keyPath, result)
keyPath.pop()
}
return iterationResult
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment