I am new in js programming and i have some problem. This example is trivialization of my problem. Here's function:
function sendOrder(){
var someObject = {items:[]};
$(document).ready(function(){
// pushing some item to array in object
someObject.items.push({Name: "Orange", Quantity: 2, OrderUnit: "kg"});
});
// pushing second item to array in object
someObject.items.push({Name: "Lemon", Quantity: 3, OrderUnit: "kg"});
console.log(JSON.stringify(someObject)); //print object
}
Result from console is:
{"items":[{"Name":"Lemon","Quantity":3,"OrderUnit":"kg"}]}
My question is: why Lemon is pushed to array in object and Orange is not?