我想複製數組中的3個對象,直到總共有50個對象。我該如何去做這件事?如何在數組中創建重複對象
var listings = [
{
address: "123 41st St",
bedrooms: 2,
bathrooms: 2,
image: "img/1bdrm_a.jpg"
},
{
address: "234 52nd St",
bedrooms: 1,
bathrooms: 1,
image: "img/1bdrm_b.jpg"
},
{
address: "345 63rd St",
bedrooms: 3,
bathrooms: 2,
image: "img/1bdrm_c.jpg"
}
];
您是否試圖自行解決方案?你卡在哪裏? –
http://jsfiddle.net/DerekL/CCfWK/ –
你是否想要一個淺拷貝(即如果'listing [0] .address'被改變,你也會在'listings [2] .address'中看到變化),或深層複製(即所有元素無關)。 – kay