I have an array
const arr = [
{
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"slug": "bitcoin",
"rank": 1,
"is_active": 1,
"first_historical_data": "2013-04-28T18:47:21.000Z",
"last_historical_data": "2022-02-18T11:39:00.000Z",
"platform": null
},
{
"id": 2,
"name": "Litecoin",
"symbol": "LTC",
"slug": "litecoin",
"rank": 20,
"is_active": 1,
"first_historical_data": "2013-04-28T18:47:22.000Z",
"last_historical_data": "2022-02-18T11:39:00.000Z",
"platform": null
}
]
And I want to transform the array to this
[{"BTC": "Bitcoin"}, {"LTC": "litecoin"}]
I tried this but no luck
const result = arr.reduce((r, c) => {Object.keys(c).map(x => {
r.push({ [x.symbol]: x.name })})})
console.log(result)