[removed] “Infinite” parameters for function?

后端 未结 3 1096
情话喂你
情话喂你 2021-01-31 14:52

In Chrome, when I type console.log in the one below:

console.log(\"A parameter\", \"A parameter\", \"A parameter\", \"A parameter\", \"A parameter\"         


        
3条回答
  •  面向向阳花
    2021-01-31 15:46

    You can use the arguments array: jsfiddle.net/kUnJ2/

    function foo() {
        for (var i = 0; i < arguments.length; i++) {
            document.body.innerHTML += arguments[i];
        }
    }
    
    
    foo("There ", "are ", "as ", "much ", "arguments ", "as ", "you ", "want.");
    

提交回复
热议问题