Here is an example of a JSON file:
[
{
"stores": [
{
"name" : "My store",
"location" : "NY"
},
{
"name" : "Other store",
"location" : "FL"
},
{
"name" : "My other store",
"location" : "NY"
}
],
},
{
"stores": [
{
"name" : "Another My store",
"location" : "NY"
},
{
"name" : "Some Other store",
"location" : "FL"
},
{
"name" : "Secondary store",
"location" : "NY"
}
],
}
]
The goal is to combine the data into one single array:
[
{
"name" : "My store",
"location" : "NY"
},
{
"name" : "Other store",
"location" : "FL"
},
{
"name" : "My other store",
"location" : "NY"
},
{
"name" : "Another My store",
"location" : "NY"
},
{
"name" : "Some Other store",
"location" : "FL"
},
{
"name" : "Secondary store",
"location" : "NY"
}
]
I am currently working on a loop to achieve this, but I am unsure how to group all the items together:
const input = [
{
"stores": [
{
"name" : "My store",
"location" : "NY"
},
{
"name" : "Other store",
"location" : "FL"
},
{
"name" : "My other store",
"location" : "NY"
}
],
},
{
"stores": [
{
"name" : "Another My store",
"location" : "NY"
},
{
"name" : "Some Other store",
"location" : "FL"
},
{
"name" : "Secondary store",
"location" : "NY"
}
],
}
];
let grouped = []
input.forEach(item => {
const store = Object.keys(item.stores)
console.log(store)
})