var cartArray = [];
//in a loop
var cartObject = {};
cartObject.item_name = 'NAME';
cartObject.quantity = number;
cartObject.amount = number;
cartObject.total = cart.amount * cart.quantity;
cartObject.subtotal = cart.subtotal + cart.total;
// store
cartArray[i]=cartObject;
can we directly store like on the fly without having full information of cartObject
var cartArray=[]
cartArray[i].item_name ='NAME'
cartArray[i].quantity =number
this thing works like
var cartArray=[]
cartArray[i]={}// it needs to be defined for each i
cartArray[i].item_name ='NAME'
cartArray[i].quantity =number
can we bypass this thing
cartArray[i] = {item_name: 'NAME', quantity: number, …};?cartArray[i].discount = numberassignment to succeed. If you did create the objects in the first loop, and then afterwards add a new.discountproperty to them, it will work just fine. Did you try it?undefineduntil the point where you get the information).