How to pass in multiple values for a function to be handled by the methods within the function.

A delete method for js. I want to pass in N values. Could you tell me how to write the method of passing values? I don"t know if it"s okay to use an array. No, no, no.


remove:function (obj) {  
        var obj=[];
        for(var i=0;i<obj.length;iPP){
        obj.parentNode.removeChild(obj)
        };
    }

Obj
    remove(obj.obj.obj......);
Mar.03,2021

use rest parameter to turn the input parameters into an array

remove:function (...obj) {  
        for(var i=0;i<obj.length;iPP){
            obj.parentNode.removeChild(obj)
        };
    }
remove(1,2,3,4,5);

search arguments


1. You can use an array

remove:function (data) {  
        for(var i=0;i<data.length;iPP){
        obj.parentNode.removeChild(data[i])
        };
    }

when calling, obj.remove directly ([1Jing 2Jing 3Jing 4])

Menu