Given a JSON object, how would you merge the batter array and topping array within the object. I know I can do let x = foo.batters.batter.concat(foo.topping), which will give me an array of the merged array but what if I wanted it within object?
foo = {
"id": "0001",
"type": "donut",
"name": "Cake",
"ppu": 0.55,
"batters":
{
"batter":
[
{ "id": "1001", "type": "Regular" },
{ "id": "1002", "type": "Chocolate" },
{ "id": "1003", "type": "Blueberry" },
{ "id": "1004", "type": "Devil's Food" }
]
},
"topping":
[
{ "id": "5001", "type": "None" },
{ "id": "5002", "type": "Glazed" },
{ "id": "5005", "type": "Sugar" },
{ "id": "5007", "type": "Powdered Sugar" },
{ "id": "5006", "type": "Chocolate with Sprinkles" },
{ "id": "5003", "type": "Chocolate" },
{ "id": "5004", "type": "Maple" }
]
}
batterarray ortoppingarray -- either or, just curious as to how to do itfoo.batters.batteror infoo.toppingor infoo.newOne, ? , and what will happent to previous lists ?foo.batters.batter = foo.batters.batter.concat(foo.topping)