const data = [
{
'UTMEH5': {
descr: {
ordertype: 'limit',
pair: 'XBT/USD',
price: '5000.00000',
},
status: 'open',
vol: '0.00200000',
},
},
{
'3F2TYE': {
descr: {
ordertype: 'limit',
pair: 'XBT/USD',
price: '10000.00000'
},
status: 'open',
vol: '0.00200000',
},
},
]
const orders = data.map((order) => {
return Object.entries(order).map(([key, value]) => ({
orderid: key,
pair: value['descr']['pair'],
vol: value['vol'],
price: value['descr']['price'],
ordertype: value['descr']['ordertype'],
status: value['status'],
}))})
console.log(orders)
With the above code I am getting this:
[
[
{
"orderid": "UTMEH5",
"pair": "XBT/USD",
"vol": "0.00200000",
"price": "5000.00000",
"ordertype": "limit",
"status": "open"
}
],
[
{
"orderid": "3F2TYE",
"pair": "XBT/USD",
"vol": "0.00200000",
"price": "10000.00000",
"ordertype": "limit",
"status": "open"
}
]
]
but I want this:
[
{
"orderid": "UTMEH5",
"pair": "XBT/USD",
"vol": "0.00200000",
"price": "5000.00000",
"ordertype": "limit",
"status": "open"
},
{
"orderid": "3F2TYE",
"pair": "XBT/USD",
"vol": "0.00200000",
"price": "10000.00000",
"ordertype": "limit",
"status": "open"
}
]
With the duplicate suggestion it looks like I can use .flat()
, but that seems like a roundabout way to get what I'm looking for. Is there a better more straightforward way?