移除數(shù)組 arr 中的所有值與 item 相等的元素,直接在給定的 arr 數(shù)組上進(jìn)行操作,并將結(jié)果返回
function removeWithoutCopy(arr, item) {
for(var index of arr){
if(arr[index] == item){
arr.splice(index,1)
}
}
return arr
}
for of是ES6提供的方法,部分低版本瀏覽器無法支持