Passing an array as a function parameter in JavaScript

前端 未结 10 2396
-上瘾入骨i
-上瘾入骨i 2020-11-22 10:35

I\'d like to call a function using an array as parameters:

const x = [\'p0\', \'p1\', \'p2\'];
call_me(x[0], x[1], x[2]); // I don\'t like it

function call_         


        
10条回答
  •  被撕碎了的回忆
    2020-11-22 11:02

    Note this

    function FollowMouse() {
        for(var i=0; i< arguments.length; i++) {
            arguments[i].style.top = event.clientY+"px";
            arguments[i].style.left = event.clientX+"px";
        }
    
    };
    

    //---------------------------

    html page

    
    
    

    Follow1

    Follow2

    Follow3

    can call function with any Args

    
    

    or

    
    

提交回复
热议问题