im trying to build a cart functionality where the user would add a single product to an array of products or objects.
var product = {
"Name": "Bike",
"Price": "900",
"idproduct": "1"
};
now i would like to store this product in plain json text.Stringify function does just that.
var JsonString = JSON.stringify(product);
Now i would like to take that JsonString and convert it back to an object or object array like so.
var JsonObjectArray = JSON.parse(JsonString);
Now im going to create a new exactly the same json object type but with diff values.
var product2 = {
"Name": "Car",
"Price": "12000",
"idproduct": "2"
};
It seems that JsonObjectArray doesnt have the push method because it got deserialized into a single object namely product1, what should i do so i can add product2 to JsonObjectArray as another member of the aray like so and repeat the process multiple times.
JsonObjectArray.push(product2);