Max
2 years agoNew Contributor II
Add key to array of objects
Hello,
I have an array of objects that i need to simply add a key to. However, im not a able to find a way of doing this. attached are screen shots of the input and desired output. Any advise is much appreciated.
Input:
[
{
fromCurrency:{
code: "CUC",
name: "Cuban convertible peso"
},
toCurrency:{
code: "CLP",
name: "Chilean peso"
},
balanceSheetRate: 672.98,
exchangeRate: 670.894,
lastUpdatedDate: "2021-05-20",
effectiveDate: "20231201184413"
},
{
fromCurrency:{
code: "BTC",
name: "Bitcoin"
},
toCurrency:{
code: "MTL",
name: "Maltese lira"
},
balanceSheetRate: 0.91050133,
exchangeRate: 0.93682458,
lastUpdatedDate: "2021-05-19",
effectiveDate: "20231201184413"
}]
Desired output:
{
"exchangeRates": [
{
"fromCurrency": {
"code": "TWD",
"name": "New Taiwan dollar"
},
"toCurrency": {
"code": "AZN",
"name": "Azerbaijani manat"
},
"exchangeRate": 0.05271961,
"balanceSheetRate": 0.05239825,
"lastUpdateDate": "2023-11-02",
"effectiveDate": "20231201184413"
},
{
"fromCurrency": {
"code": "YER",
"name": "Yemeni rial"
},
"toCurrency": {
"code": "CDF",
"name": "Congolese franc"
},
"exchangeRate": 9.96723124,
"balanceSheetRate": 10.30493871,
"lastUpdateDate": "2023-11-02",
"effectiveDate": "20231201184413"
}]