1let person = {
2 name : 'John Doe',
3 age : 35
4}
5
6//Now we can add element by 2 ways
7person.occupation = 'Web Designer'
8//or
9person['occupation'] = 'Web Designer'; //This is usefull for adding element within loop.
10
11object[yourKey] = yourValue;
12object.yourKey = yourValue;
13
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});