I am trying to de-structure an array of object and create sub objects from it I have an array an object like
const data = [
{
"id": 1,
"locationone": "California, United States",
"idtwo": 2,
"locationtwo": "Atherton, United States"
},
{
"id": 3,
"locationone": "London",
"idtwo": 4,
"locationtwo": "New Jersey"
}
]
I am trying to achieve the following result
[
{
id : 1,
location : "California, United States"
},
{
id : 2,
location : "Atherton, United States"
},
{
id : 3,
location : "London"
},
{
id : 4,
location : "New Jersey"
},
]
I tried the following approach but it didn't work
const result= data
.map(({ id,locationone, idtwo, locationtwo }) => ({
name: locationone,
id: id,
name: locationtwo,
id : idtwo
}))
Also is there a way that newly created result array has only elements with unique id?