Here is what my object looks like:
let myObj = {
"Accounts": [
{
"Type": "Card",
"CreditCard": {}
},
{
"Type": "ACH",
"CreditCard": {}
},
{
"Type": "CDA",
"Checking": {}
},
{
"Type": "INTL",
"Mortgage": {}
}
]
}
I'd like to change the property name from CreditCard,Checking,Mortgage
to something common such as FinanceRecord
. I know I can do something like below
let temp = myObj.map(({ CreditCard: FinanceRecord, ...item }) => ({
FinanceRecord,
...item,
}));
// Specify each property name...
myObj.map(({ Checking: FinanceRecord, ...item }) => ({
FinanceRecord,
...item,
}));
Is there any better way to do this? I have about 20 different property names which I want to update. Thanks!
Edit:
Expected Output:
let myObj = {
"Accounts": [
{
"Type": "Card",
"FinanceRecord": {}
},
{
"Type": "ACH",
"FinanceRecord": {}
},
{
"Type": "CDA",
"FinanceRecord": {}
},
{
"Type": "INTL",
"FinanceRecord": {}
}
]
}