Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. const flatten = obj =>
  2. Object.keys(obj).reduce((acc, current) => {
  3. const key = `${current}`;
  4. const currentValue = obj[current];
  5.  
  6. if (typeof currentValue === 'object') {
  7. Object.assign(acc, flatten(currentValue));
  8. } else {
  9. acc[key] = currentValue;
  10. }
  11.  
  12. return acc;
  13. }, {});
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement