I'm looking to convert all keys of my array of objects into camelCase using TypeScript. Here is the data I have:
[
{
"Name":"Custom property",
"Details":{
"Address":"Huston",
"Price":"1000000",
},
"Contact":{
"Global":"3432432",
"Local":"432423423"
},
},
{
"Name":"Myproperty",
"Details":{
"Address":"Huston",
"Price":"10000001",
},
"Contact":{
"Global":"34324323",
"Local":"4324234233"
},
},
]
Although I attempted the code below, it only returns a new dictionary with the details. How can I fix this issue?
const newObjOptions = options.map((obj: any) =>
Object.fromEntries(
Object.entries(obj).map(([k, v]) => [_.camelCase(k), v])
)
);
const newObjDetailsOptions = newObjOptions.map((obj: any) =>
Object.fromEntries(
Object.entries(obj.details).map(([k, v]) => [_.camelCase(k), v])
)
);