Remove specific element by editing the array

来源:互联网 发布:bbc纪录片中国网络支付 编辑:程序博客网 时间:2024/06/04 20:01
function removeWithoutCopy(arr, item) {    for(var i=0;i<arr.length;i++){        if(arr[i]===item){            arr.splice(i,1);                i--;        }    }    return arr;}

The function splice() will change the original array and then return the elements which had been deleted(If exist).

0 0
原创粉丝点击