Is there a way to capitalize the first letter of every key in an array of objects? I attempted to achieve this with the code below, but it's not working as expected.
Any suggestions or corrections are appreciated. #current code
function capitalizeObjectKeys(obj) {
return _.transform(obj, function (result, val, key:any) {
result[key.charAt(0).toUpperCase() + key.slice(1)] = val;
});
}
#sample object
[{
"id": 3,
"accountId": 6,
"title": "ABCDF Copy",
"versionDto": {
"id": 3,
"entitlementsTemplateId": 3,
"status": "Draft",
"entitlementElementsTemplateDto": [
{
"id": 5,
"isHeaderCategory": false,
"order": 1,
},
{
"id": 6,
"isHeaderCategory": false,
"order": 2,
}
]
}
}]
#expected output
[{
"Id": 3,
"AccountId": 6,
"Title": "ABCDF Copy",
"VersionDto": {
"Id": 3,
"EntitlementsTemplateId": 3,
"Status": "Draft",
"EntitlementElementsTemplateDto": [
{
"Id": 5,
"IsHeaderCategory": false,
"Order": 1,
},
{
"Id": 2,
"IsHeaderCategory": false,
"Order": 2,
}
]
}
}]