I have a map containing key-value pairs as shown below:
for (let controller of this.attributiFormArray.controls) {
attributiAttivitaMap.set(controller.get('id').value, { value: controller.get('valoreDefault').value, mandatory: controller.get('obbligatorio').value })
}
After setting the values in my map, it looks like this:
0 : key: 10, value: {value: 200, mandatory: false}
1 : key: 102, value: {value: 300, mandatory: false}
Now, my goal is to create a list of objects in the following format:
"valoriDefaultAttributiAttivita" : {
"10" : {"value" : "200", "mandatory": false},
"102" : {"value" : "300", "mandatory": false},
}
where "10" and "102" are the keys from my map.
I've attempted various methods, but when I try to convert it into an array, I struggle to set the key value as a property. Any suggestions on how I can achieve this?
let array: any[] = [];
for(let key of attributiAttivitaMap.keys()){
array.push({key: attributiAttivitaMap.get(key)});
}