Created
August 31, 2018 18:34
-
-
Save RavenHursT/8f15064739b873302c4e6547d9f10426 to your computer and use it in GitHub Desktop.
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
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