I need to add new key/value pair into nested object array.
this is exisiting array
[{
"featureId": "67d6e1bf-3919-4dcc-b636-236ab41d431b",
"featureName": "Test name 1",
"rules": [
{
"ruleId": "a9ab3ce2-e69c-4c0c-b561-1107baed1e68",
"ruleName": "Sub test 1",
},
{
"ruleId": "a9ab3ce2-e69c-4c0c-b561-1107baed1e68",
"ruleName": "Sub Test 2",
},
{
"ruleId": "a8003493-4471-4c8a-85c1-b15706359bb3",
"ruleName": "Sub Test Three",
}
]
},
{...}
]
I need to add additional property into the rules object items.
Expected output is
[{
"featureId": "67d6e1bf-3919-4dcc-b636-236ab41d431b",
"featureName": "Test name 1",
"rules": [
{
"ruleId": "a9ab3ce2-e69c-4c0c-b561-1107baed1e68",
"ruleName": "Sub test 1",
"temp_id" : 1
},
{
"ruleId": "a9ab3ce2-e69c-4c0c-b561-1107baed1e68",
"ruleName": "Sub Test 2",
"temp_id" : 1
},
{
"ruleId": "a8003493-4471-4c8a-85c1-b15706359bb3",
"ruleName": "Sub Test Three",
"temp_id" : 1
}
]
},
{...}
]
I need to add temp_id property dynamically. I tried below its not working as expected
Object.keys(_this.existingConfigurations).map((key)=>_this.existingConfigurations[key].rules).reduce((n,id)=>n).map((ny,ni)=>{return {...ny, temp_id : uuid.v4()}});
Here "_this.existingConfigurations" is variable which have the data, i need to do above modification and send to next level.