1{
2 "cars": {
3 "Nissan": [
4 {"model":"Sentra", "doors":4},
5 {"model":"Maxima", "doors":4},
6 {"model":"Skyline", "doors":2}
7 ],
8 "Ford": [
9 {"model":"Taurus", "doors":4},
10 {"model":"Escort", "doors":4}
11 ]
12 }
13}
1{
2 "cars": {
3 "Nissan": {
4 "Sentra": {"doors":4, "transmission":"automatic"},
5 "Maxima": {"doors":4, "transmission":"automatic"}
6 },
7 "Ford": {
8 "Taurus": {"doors":4, "transmission":"automatic"},
9 "Escort": {"doors":4, "transmission":"automatic"}
10 }
11 }
12}
13
14data.cars['Nissan']['Sentra'].doors // 4
15data.cars['Nissan']['Maxima'].doors // 4
16data.cars['Nissan']['Maxima'].transmission // automatic
17
18for (var make in data.cars) {
19 for (var model in data.cars[make]) {
20 var doors = data.cars[make][model].doors;
21 alert(make + ', ' + model + ', ' + doors);
22 }
23}
1data.cars['Nissan'][0].model // Sentra
2data.cars['Nissan'][1].model // Maxima
3data.cars['Nissan'][2].doors // 2
4
5for (var make in data.cars) {
6 for (var i = 0; i < data.cars[make].length; i++) {
7 var model = data.cars[make][i].model;
8 var doors = data.cars[make][i].doors;
9 alert(make + ', ' + model + ', ' + doors);
10 }
11}