Currently, I am facing an issue with an empty JSON array.
shoppingCart: []
In addition to the empty array, I also have a JSON object defined as follows:
let product = {"name": "name", "price": "price", "quantity": "quantity", "logoPath": "logoPath"};
My objective is to add this JSON object to the existing array. To achieve this, I have written the following code snippet:
let obj = JSON.parse(state.shoppingCart);
obj.push(product);
state.shoppingCart = JSON.stringify(obj);
Despite my efforts, I encountered the following error message:
"SyntaxError: Unexpected end of JSON input"
Ultimately, I aim to populate the empty array with multiple objects like the example shown below:
shoppingCart: [{id: 1, name: name1}, {id: 2, name: name2}, {id: 3, name: name3}]
Can you please help me identify where I may have made a mistake in my approach?