I am facing an issue while attempting to form sets of objects in an array and generating a new set if the item is not already present.
The structure of the data looks something like this:
[
{
"order": orderData,
"items": itemData
}, {
"order": orderData,
"items": itemData
}
]
However, when I try to create a new array index dynamically and attempt to add items to it, I encounter the error below:
Cannot set property 'items' of undefined
In the scenario, setNo = 2
, but this.cart[2]
has not been initialized yet.
this.cart[setNo]['items'].push(items);
How can I properly initialize this index so that items can be added to it dynamically?