-1
我有这个功能,我想重新排列数组中最后找到的所有0,我正在使用一个临时数组。一切都很好,直到我检查了testArray
这是作为参数收到的原始数组的长度。为什么我找不到他的长度以及第一个for
如果他的长度未定义如何工作?无法获得作为参数收到的数组的长度
window.onload = function() {
var testArray =[5,3,0,55,0,9,0,8];
function moveArray(testArray){
var tempArray= [];
console.log(tempArray.length + " vs " + testArray.lenght);
for(var i = 0 ;i < testArray.length; i++) {
if(testArray[i] != 0){
tempArray.push(testArray[i]);
// console.log("pushed " + testArray[i]);
}
}
// console.log(tempArray.length + " vs " + testArray.lenght);
while(tempArray.length < testArray.lenght){
tempArray.push('0');
// console.log('push 0');
}
testArray=tempArray;
for(var i = 0 ;i < testArray.length; i++){
// console.log(testArray[i]);
}
};
moveArray(testArray);
};
你只是想移动的0到最后还是你也想的其余值排序? – charsi
'lenght' **长度** –
testArray.lenght?它应该是testArray.length – Oxi