Here is the data I have:
let myInputArray = [
{
"id": 1,
"commercialRanges": [
{
"rangeId": "305",
"rangeName": "FIXE"
},
{
"rangeId": "306",
"rangeName": "POSTPAID"
},
],
"active": true,
"pefName": "Alertes",
"roles": "ADVISOR",
"equipmentTypes": "PC",
},
...
{
"id": 1523,
"commercialRanges": [
{
"rangeId": "700",
"rangeName": "POSTPAID"
},
{
"rangeId": "500",
"rangeName": "PREPAID"
},
]
,
"active": true,
"pefName": "Alertes",
"roles": "ADVISOR",
"equipmentTypes": "PC",
},
]
I am looking to transform my data by converting the "commercialRanges" attribute from an array of objects to a simple string that joins the different "rangeName" values.
The resulting array would look like this:
myResultArray = [
{
"id": 1,
"commercialRanges": "FIXE,POSTPAID",
"active": true,
"pefName": "Alertes",
"roles": "ADVISOR",
"equipmentTypes": "PC",
},
...
{
"id": 1523,
"commercialRanges": "POSTPAID,PREPAID",
"active": true,
"pefName": "Alertes",
"roles": "ADVISOR",
"equipmentTypes": "PC",
},
]
This means converting the embedded object "commercialRanges"
"commercialRanges": [
{
"rangeId": "305",
"rangeName": "FIXE"
},
{
"rangeId": "306",
"rangeName": "POSTPAID"
},
]
to:
"commercialRanges": "FIXE,POSTPAID"