0
我想推動數組A到B內循環,然後和B的每次迭代我需要刪除數組A並創建一個新的。我清除陣列之前獲得的所有數據,但清理後,我得到空值推送到另一個陣列後的空陣列
B陣列代碼:
for (i = 0; i < XArray.length; i++) {
var pointsArray = [];
for (j = 0; j < XArray.length; j++) {
if (XArray[i] == XArray[j]) {
pointsArray.push([parseFloat(YArray[i]), parseFloat(ZArray[i])]);
}
}
dataSource.push({
name: i,
data: pointsArray
});
pointsArray.length = 0;
}
或者使用'slice' - >'data:pointsArray.slice()'複製一份副本' – Xotic750
鞠躬主。+ 1 –
pointsCopy = pointsArray.slice(); dataSource.push({name:i,data:pointsCopy}); pointsArray.length = 0; –