In Chrome, when I type console.log
in the one below:
console.log(\"A parameter\", \"A parameter\", \"A parameter\", \"A parameter\", \"A parameter\"
The modern way of doing this is using rest parameters:
function printArguments(...args) {
args.forEach((arg, index) => {
console.log(`Argument ${index}:`, arg);
});
}
printArguments('hello', true, new Date());
By using the ...args
syntax, all parameters are saved in an array named args
.
Except of Internet Explorer, all browsers already ship this feature in their newest version.
Fiddle: https://jsfiddle.net/Lbf0stst/