how to add to a object in javascript code example
Example 1: javascript add to object
var element = {}, cart = [];
element.id = id;
element.quantity = quantity;
cart.push(element);
// Array of Objects in form {element: {id: 10, quantity: 10} }
var element = {}, cart = [];
element.id = id;
element.quantity = quantity;
cart.push({element: element});
Example 2: js create object with properties
function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}