Destroyer function help

function destroyer(arr){
    let len = arguments.length;
    let arry = [];
    let mainArr = arguments[0];
    for(let i = 1;i< len;i++){
       arry.push(arguments[i])
    }
    console.log(mainArr);
    for(let x =0;x<mainArr.length+1;x++){
        for(let j=0;j<arry.length;j++){
            if(mainArr[x] === arry[j]){
                mainArr.splice(mainArr.indexOf(arry[x]),1);
            } 
        }    
    }
   
   
   console.log(mainArr);
};

so this function an array followed by extra some arguments. I need to remove element of this array which is same as those extra argument. So, I create this function but the result I get is

[1,2]

Please anyone tell me why last 2 isn’t remove?

Could you please post the code that shows the arguments? Currently your function’s only parameter is an array. Your reference to arguments will be undefined right now. Perhaps you are looking to use the rest operator in your function? Something like this:

function destroyer(arr, ...args) { // rest of your code }

destroyer([3, 5, 1, 2, 2], 2, 3, 5);

Sorry I forgot to post arguments