Currently, I am working with Angular 12 within my TS file and have encountered an array response from a file upload that looks like this-
[
{
"id": "7",
"name": "xyz",
"job": "doctor",
"preference": "1"
},
...
]
My goal is to convert this array into a JSON object structure as follows-
[
{
"id": "7",
"name": "xyz",
"array1": [
{
"date": "today's Date,",
"endDate": "somedate",
"lastUpdatedBy": "someuser",
"array2": [
{
"job": "doctor",
"preference": "1"
},
...
]
}
]
}
]
I am struggling to achieve this transformation using map or arrays nesting due to the challenge of avoiding duplicate keys for the same id and name combination. Your assistance in tackling this issue would be highly appreciated.
Below is a snippet of the code I have been attempting to modify:
let object = {
id: data[i].id,
name: data[i].name,
array1:[
{
date: dateParam,
endDate: '',
lastUpdatedBy: 'me',
array2: [
{
job: data[i].job,
preference: data[i].preference
}
]
}
]
};