Reputation: 4480
Suppose we have a function(a, b, c, d, e...){console.log(a,b,c,d,e)}
This will console.log inline the variables a,b,c,d,e
but if the function were to have argument f
passed to it (or more arguments) it would not be logged.
The following will log everything:
console.log(arguments)
but it is displayed as a Arguments[] object.
I have also tried:
for (let i = 0; i < arguments.length; i++) {
console.log(arguments[i]);
}
Which will log every argument but each on a new line. Is it possible to console.log
all arguments inline when the number of arguments is arbitrary?
Upvotes: 0
Views: 369
Reputation: 370609
Spread the arguments
into the console.log
call:
function(a, b, c, d, e){
console.log(...arguments);
}
Or, use rest parameters
function(...args){
console.log(...args);
}
Upvotes: 2