Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

unlimited optional arguments js

// arguments is "like" an array that stores all arguments given to manyArgs
// (User can invoke manyArgs with arguments even though none are specified)
function manyArgs() {
  for (var i = 0; i < arguments.length; ++i)
    alert(arguments[i]);
}
// Note: for arrow functions you must do
let manyArgs = (concreteArg1, concreteArg2, ...rest) => {
  for (var i = 0; i < rest.length; ++i)
    alert(rest[i]);
  	// concreteArgs are not included in rest "array"
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #unlimited #optional #arguments #js
ADD COMMENT
Topic
Name
6+9 =