如何迭代JavaScript中的一組字面對象?將對象推入數組意外的結果
我願做這樣的事情:
grupo = []; // declare array
text = {}; // declare new object
text.a = "texta"; // declare property "a" of an object.
text.b = "textb";
grupo.push(text); // add object to array
text = {}; // declare new object
text.a = "textc"; // declare property
grupo.push(text); // add object with other property
// Iterate over
for (i=0; i<=grupo.length; i++) {
console.dir(grupo[i].text.a);
}
負,但沒有解釋爲什麼,我討厭這樣。 –
for(var i = 0; i
Baseleus
不是同一個問題...也許我沒有正確解釋,即時迭代時需要訪問對象上的屬性。 –