how to add object values in javascript code example
Example 1: how to add field to object in js
var obj = {
key1: "a",
key2: "b"
};
obj.key3 = "c";
obj["key3"] = "c";
console.log(obj)
Example 2: object object javascript
person = {
'name':'john smith'
'age':41
};
console.log(person);
console.log(JSON.stringify(person));
Example 3: how to add items to object in javascript
var element = {}, cart = [];
element.id = id;
element.quantity = quantity;
cart.push(element);
var element = {}, cart = [];
element.id = id;
element.quantity = quantity;
cart.push({element: element});
Example 4: js add data in object
var element = {}, cart = [];
element.id = id;
element.quantity = quantity;
cart.push(element);