你好,我不確定爲什麼那些空的元素仍然存在,即使我清除(或清除函數不工作猜測)。可能你們看看這個。我得到這個陣列添加其他值後進入同array.I要問什麼正在發生的事情的背後不只是解決代碼謝謝清除數組中的空元素
這個功能當過我按一下按鈕,它增加了四成DVALUE陣列。
if("q"+idcount+"d" == this.id){
DVALUE[dcount++] = 4;
// alert("D ARRAY"+DVALUE.toString());
}
這就是當過我點擊回覆按鈕,它會刪除最後添加的數量
if ("d" === qwer) {
// alert(""+DVALUE.toString());
DVALUE.pop();
cleararrayD(); // also calling this function to remove empty elements when ever this if occurs
}
這是cleararrayD功能
function cleararrayD() {
lens = DVALUE.length, i;
for (i = 0; i < lens; i++) DVALUE[i] && DVALUE.push(DVALUE[i]); // copy non-empty values to the end of the array
DVALUE.splice(0, lens);
}
任何建議的代碼? –
什麼是輸入和預期結果? – guest271314
輸入只是數字和結果有點複雜我得到所有這些數字索引應該有0-11索引,所有索引都有數字,這就是爲什麼我需要清空空元素,否則我得到未定義。 –