javascript add to object

JavaScript
var element = {};
element.push({ id: id, quantity: quantity });
cart.push(element);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});
Source

Also in JavaScript: