var array = [{}];
var obj = {
name: "Fred X",
age: 20
}
function x() {
array[1].name = "Alice";
array[1].age = 48;
}
array[0] = obj;
document.write(array[0].name + "=" + array[0].age, "<br>");
array[1] = obj;
x();
document.write(array[0].name, "=", array[0].age < br > ",array[1].name,"=",array[1].age);
I am trying to construct a shopping cart with an array of items (objects with properties) but it is not working. The code above illustrates the problem: when I try to read out the cart, all items appear like the last added one. What am i not getting here? Thanks in advance ...