Skip to content

Instantly share code, notes, and snippets.

@OmisNomis
Created March 8, 2018 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OmisNomis/862a63eacbc0e08a25d60d91b410f37c to your computer and use it in GitHub Desktop.
Save OmisNomis/862a63eacbc0e08a25d60d91b410f37c to your computer and use it in GitHub Desktop.
Recursion Function
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