I'm including what I think are the important bits of code below...
updates = {};
products = {};
newProducts = category.items[0].items;
oldProducts = categoryData[i][0].items;
itemsObj = {};
updates['changes'] = [];
Followed by a bunch of code that adds items to 'changes' such as...
itemsObj['update'] = "modify";
itemsObj['id'] = oldProduct.id;
itemsObj['type'] = oldProduct.type;
itemsObj['qty'] = newProduct.qty;
updates['changes'].push(itemsObj);
After all the updates, I called an alert below during testing. When I later attempted to remove it I found I no longer got the 'changes' above.
alert(JSON.stringify(updates));
If I don't do the alert above then 'updates' (ultimately updateJSON) only returns 'productRequest' below, not 'changes' above. I've tried setting the stringified version of updates to another variable, logging to console, and some other hacky ways I found online but only the above alert works for me. Obviously there's a way to fix this and I can't have an alert firing in production.
products['action'] = "editProducts";
products['id'] = xxxxxxxx;
updates['productRequest'] = products;
updateFinal = JSON.stringify(updates);
consoleLog(updateFinal);
Anyone have what I expect is an easy solution?