Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140161

Create nested object from array of objects in JavaScript [closed]

$
0
0

I have array of objects data:

[
  {"company": "Google", "country": "USA", "employee": "John"},
  {"company": "Amazon", "country": "UK", "employee": "Arya"},
  {"company": "Google", "country": "KSA", "employee": "Cersi"},
  {"company": "Amazon", "country": "USA", "employee": "Tyrion"},
  {"company": "Amazon", "country": "USA", "employee": "Daenarys"},
  {"company": "Google", "country": "KSA", "employee": "Dothrokhi"}
]

How can I create a nested object like below?

{
  "Amazon": {
    "UK": {"Arya": null}, 
    "USA": {"Tyrion": null, "Daenarys": null}
  },
  "Google": {
    "KSA": {"Cersi": null, "Dothrokhi": null},
    "USA": {"John": null}
  }
}

Viewing all articles
Browse latest Browse all 140161

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>