I need to combine the gid and subGroups and output it into an array of strings without duplication.
My problem now is that it only gets the first level.
const oldGroup = [
{
"gid": "JFK",
"subGroups": [
"SFO",
"LAX"
]
},
{
"gid": "JFK",
"subGroups": [
"SFO",
"LAX"
]
},
{
"gid": "SFO",
"subGroups": []
},
{
"gid": "LAX",
"subGroups": [
"LGA"
]
}
]
const newGroup = [...new Set(oldGroup.map((group) => group.gid))]
console.log(newGroup)
const newGroup = Array.from(new Set(oldGroup.flatMap(({ gid, subGroups }) => subGroups.map((item) => `${gid} → ${item}`))))?