How to get the number of arguments of a function with dynamic number of arguments in JavaScript

2 Answers

0 votes
function f(...args) {
    console.log(args);

    return arguments.length;
}
 
console.log(f(1, 4, 5, 7, 3, 9));
 
 
 
/*
run:
 
[ 1, 4, 5, 7, 3, 9 ]
6
 
*/

 



answered Mar 4, 2020 by avibootz
0 votes
function f(/*...*/) {
    return arguments.length;
}
 
console.log(f(1, 4, 5, 7, 3, 2, 98));
 
 
 
/*
run:
 
7
 
*/

 



answered Mar 4, 2020 by avibootz
...