1// original object { key1: "a", key2: "b"}
2var obj = {
3 key1: "a",
4 key2: "b"
5};
6
7// adding new filed - you can use 2 ways
8obj.key3 = "c"; // static
9// or
10obj["key3"] = "c"; // dynamic - 'key3' can be a variable
11console.log(obj) // {key1: "a", key2: "b", key3: "c" }
1var element = {}, cart = [];
2element.id = id;
3element.quantity = quantity;
4cart.push(element);
5
6// Array of Objects in form {element: {id: 10, quantity: 10} }
7var element = {}, cart = [];
8element.id = id;
9element.quantity = quantity;
10cart.push({element: element});