1var obj = {
2 prop1: 5,
3 obj2: {
4 prop1: [3, 6, 3],
5 prop2: 74,
6 prop3: {
7 str: "Hello World"
8 }
9 }
10};
11
12console.log(obj.obj2.prop3.str); //output: "Hello World"
1var obj = {
2 func: function(a, b) {
3 return a * b;
4 }
5};
6
7obj.func(3, 6); // 18
1let object = {
2 'key1': 'value1',
3 'key2': 'value2',
4 'keyn': 'valuen',
5};
6console.log(object);
1person = {
2 'name':'john smith'
3 'age':41
4};
5
6console.log(person);
7//this will return [object Object]
8//use
9console.log(JSON.stringify(person));
10//instead
1var nbo = { name: "Nairobi" };
2var mba = { name: "Mombasa" };
3var kis = { name: "Kisumu" };
4var qsi = { name: "Moshi" };
5var dar = { name: "Dar Es Salaam" };
6
7
8var kenya = { name: "Kenya", cities: [nbo, mba, kis] };
9var tanzania = { name: "Tanzania", cities: [qsi, dar] };
10var rwanda = { name: "Rwanda", cities: [] };
11kenya.cities.forEach(function(city) {
12 console.log("Let's go to " + city.name + "!");
13});
14
15var kgl = { name: "Kigali" };
16rwanda.cities.push(kgl);