xxxxxxxxxx
var element = {}, cart = [];
element.id = id;
element.quantity = quantity;
cart.push({element: element});
xxxxxxxxxx
// Create an empty object
const myObject = {};
// Add a new entry to the object
myObject.newEntry = "This is a new entry";
// You can also use square brackets to add a new entry with a dynamic property name
const dynamicPropertyName = "anotherEntry";
myObject[dynamicPropertyName] = "This is another new entry";
// Now, you can access these entries
console.log(myObject.newEntry); // Output: "This is a new entry"
console.log(myObject.anotherEntry); // Output: "This is another new entry"