递归,如果能找到序号就删除对应序号的元素,然后继续调用方法,找不到就返回数组
function removeWithoutCopy(arr, item) {
let index = arr.indexOf(item)
if (index >= 0) {
arr.splice(index, 1)
return removeWithoutCopy(arr, item)
} else {
return arr
}
}
递归,如果能找到序号就删除对应序号的元素,然后继续调用方法,找不到就返回数组
function removeWithoutCopy(arr, item) {
let index = arr.indexOf(item)
if (index >= 0) {
arr.splice(index, 1)
return removeWithoutCopy(arr, item)
} else {
return arr
}
}