Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript take any number of arguments

function sum() {
  // "arguments" is an object that can be converted to an Array
  const args = Array.from(arguments);
  return args.reduce((acc, next) => acc + next);
}

sum(1, 2);       // 3
sum(1, 2, 3);    // 6
sum(1, 2, 3, 4); // 10
Comment

Javascript function method with any number of arguments

function foo() {
  for (var i = 0; i < arguments.length; i++) {
    console.log(arguments[i]);
  }
}
Comment

unlimited number of arguments in function javascript

function manyArgs() {
  for (var i = 0; i < arguments.length; ++i)
    alert(arguments[i]);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to check for special charaters with spaces javascript 
Javascript :: waypoint 
Javascript :: javascript switch statement 
Javascript :: empty string in javascript 
Javascript :: json server start code 
Javascript :: angular cli spec test false 
Javascript :: jquery how to expand select 
Javascript :: cypress check element has an attribute 
Javascript :: async arrow function javascript 
Javascript :: slice in javascript 
Javascript :: es6 modules node 
Javascript :: js regex word before word 
Javascript :: make alphabet js 
Javascript :: Change HTML Content 
Javascript :: js split method 
Javascript :: python restapi use post json 
Javascript :: error message to show in label jquery 
Javascript :: JSX element event listeners 
Javascript :: componentdidmount in hooks 
Javascript :: nodejs remove element from array 
Javascript :: linux command to install standard js 
Javascript :: meteor create package 
Javascript :: what is ajax 
Javascript :: formgroup angular 
Javascript :: appendchild element once if element present in js 
Javascript :: what is vue.js 
Javascript :: jse api 
Javascript :: svg clientx 
Javascript :: joi validate 
Javascript :: jquery parse html 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =