I have the following object that contains objects:
{
"USD": { "7d": "32053.72", "30d": "33194.68", "24h": "31370.42" },
"AUD": { "7d": "43134.11", "30d": "44219.00", "24h": "42701.11" },
"RUB": { "7d": "2451451.45", "30d": "2465896.74", "24h": "2398589.80" },
"timestamp": 1626699964,
"JPY": { "7d": "3537735.55", "30d": "3664620.47", "24h": "3472632.46" },
"BRL": { "7d": "167555.18", "30d": "169473.27", "24h": "163054.93" },
"ILS": { "7d": "108658.72", "30d": "111663.67", "24h": "106988.58" },
"GBP": { "7d": "23257.66", "30d": "23838.55", "24h": "22923.17" },
"PLN": { "7d": "124869.61", "30d": "127872.57", "24h": "122668.16" },
"CAD": { "7d": "40425.62", "30d": "41444.76", "24h": "39827.13" },
"EUR": { "7d": "27187.74", "30d": "27955.81", "24h": "26659.79" }
}
I want to convert it to an array of objects like this:
[
{
currency: "USD",
7d: "2451451.45",
30d: "2465896.74",
24d: "42701.11"
},
{
currency: "AUD",
7d: "32053.72",
30d: "33194.68",
24d: "2398589.80"
}
]
etc, etc. This is my attempt:
var data = { "USD": { "7d": "32053.72", "30d": "33194.68", "24h": "31370.42" }, "AUD": { "7d": "43134.11", "30d": "44219.00", "24h": "42701.11" }, "RUB": { "7d": "2451451.45", "30d": "2465896.74", "24h": "2398589.80" }, "timestamp": 1626699964, "JPY": { "7d": "3537735.55", "30d": "3664620.47", "24h": "3472632.46" }, "BRL": { "7d": "167555.18", "30d": "169473.27", "24h": "163054.93" }, "ILS": { "7d": "108658.72", "30d": "111663.67", "24h": "106988.58" }, "GBP": { "7d": "23257.66", "30d": "23838.55", "24h": "22923.17" }, "PLN": { "7d": "124869.61", "30d": "127872.57", "24h": "122668.16" }, "CAD": { "7d": "40425.62", "30d": "41444.76", "24h": "39827.13" }, "EUR": { "7d": "27187.74", "30d": "27955.81", "24h": "26659.79" } }
var convertedToArray = Object.keys(data).map(key => {
return data[key];
})
It works, but for some reason the USD, AUD etc currency fields get omitted. How can I get the same output but have the currency field included?