📜  对象内的对象javascript代码示例

📅  最后修改于: 2022-03-11 15:03:11.779000             🧑  作者: Mango

代码示例4
var nbo = { name: "Nairobi" };
var mba = { name: "Mombasa" };
var kis = { name: "Kisumu" };
var qsi = { name: "Moshi" };
var dar = { name: "Dar Es Salaam" };


var kenya = { name: "Kenya", cities: [nbo, mba, kis] };
var tanzania = { name: "Tanzania", cities: [qsi, dar] };
var rwanda = { name: "Rwanda", cities: [] };    
kenya.cities.forEach(function(city) {
  console.log("Let's go to " + city.name + "!");
});

var kgl = { name: "Kigali" };
rwanda.cities.push(kgl);