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

后端 未结 12 719
[愿得一人]
[愿得一人] 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:07

    This is a sample program for calculating sum of integers for variable arguments and array on integers. Hope this helps.

    var CalculateSum = function(){
        calculateSumService.apply( null, arguments );
    }
    
    var calculateSumService = function(){
        var sum = 0;
    
        if( arguments.length === 1){
            var args = arguments[0];
    
            for(var i = 0;i

提交回复
热议问题