Is it possible to send a variable number of arguments to a JavaScript function?

后端 未结 12 1034
[愿得一人]
[愿得一人] 2020-11-22 10:51

Is it possible to send a variable number of arguments to a JavaScript function, from an array?

var arr = [\'a\',\'b\',\'c\']

var func = function()
{
    //         


        
12条回答
  •  甜味超标
    2020-11-22 11:24

    The apply function takes two arguments; the object this will be binded to, and the arguments, represented with an array.

    some_func = function (a, b) { return b }
    some_func.apply(obj, ["arguments", "are", "here"])
    // "are"
    

提交回复
热议问题