我有一個數組,我想填充,每次選擇一個新的startId和endID,但是一旦我將新對象添加到數組,我無法訪問變量在對象中,當我提醒時,我將其定義爲一個值。如何訪問數組中的對象的變量
這是我的代碼;
value = {start: this.startId, end :this.endId};
this.array[this.array.length] = value;
alert(this.array[this.array.length].start + " " + this.array[this.array.length].end)
我也試過這個
value = {start: this.startId, end :this.endId};
this.array[this.array.length] = value;
alert(this.array[this.array.length][start] + " " + this.array[this.array.length][end])
請加編程語言使用 – ianace
陣列從'0'索引,以便最後是'長 - 1' –
嘗試'警報(this.array [此。 array.length] [0] .start);' –