Created
March 8, 2018 08:33
-
-
Save OmisNomis/862a63eacbc0e08a25d60d91b410f37c to your computer and use it in GitHub Desktop.
Recursion Function
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
const flattenObject = object => { | |
let obj = {}; | |
Object.keys(object).forEach(key => { | |
if (typeof object[key] !== 'object') { | |
obj[key] = object[key]; | |
} else { | |
obj = { ...obj, ...flattenObject(object[key]) }; | |
} | |
}); | |
return obj; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment