In my @change method, I receive the following values:
changeAttr(id, key, value) {
const selections = [];
},
id can be any number, key could be: color, size, sex, etc..., and value could be: red, 8, female, etc. Initially, the values might look like this:
id = 3
,key = "color"
,value = "red"
. These values change when the user selects another option, for instance:id = 3
,key = "sex"
,value = "female"
orid = 5
,key = "size"
,value = "50"
...etc
The goal is to dynamically populate an array of objects with these values as shown below:
selections = [{
"3": {
"color": "red",
"sex": "male",
"size": "40"
},
{
...
}];
If a key already exists for the same id in the array, I want to overwrite its value. If it doesn't exist, I want to add it for that particular id.
I hope this explanation is clear. Thank you for your time!