function removeWithoutCopy(arr, item) {
for(let i = 0; i < arr.length; i++){
if(arr[i] == item){
arr.splice(i,1)
i--;//因为此处删除了一个元素,为保证索引准确,i--
}
}
return arr;//否则没有返回值
}
console.log(removeWithoutCopy([1, 2, 2, 3, 4, 2, 2], 2))
function removeWithoutCopy(arr, item) {
for(let i = 0; i < arr.length; i++){
if(arr[i] == item){
arr.splice(i,1)
i--;//因为此处删除了一个元素,为保证索引准确,i--
}
}
return arr;//否则没有返回值
}
console.log(removeWithoutCopy([1, 2, 2, 3, 4, 2, 2], 2))