Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript unknown number of parameters

function add (...numbers) {
  let sum = 0;
  for (let i = 0; i < numbers.length; i++) {
    sum += numbers[i]
  };
  console.log(sum);
};

add(2, 3);
add(5, 3, 7, 2);
Comment

Pass unknown number of arguments into javascript function

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

PREVIOUS NEXT
Code Example
Javascript :: material icon button angular 
Javascript :: update to node 15.11 
Javascript :: javascript array sorting 
Javascript :: javascript equality 
Javascript :: for...of Syntax 
Javascript :: sortable jquery 
Javascript :: node-disk-storage npm 
Javascript :: react typescript set type 
Javascript :: how to check if object exists in array javascript 
Javascript :: datatble tab bootstrap 4 
Javascript :: array.push multiple 
Javascript :: How to iterate elements in an object 
Javascript :: trigger click on first row datatable jquery 
Javascript :: react barcode scanner 
Javascript :: ng2 validations angular using reactiveforms 
Javascript :: how to write query string js 
Javascript :: nodejs express flash message 
Javascript :: How to get previous url in nextjs 
Javascript :: array in javascript 
Javascript :: express-session install 
Javascript :: react native list view 
Javascript :: copy on clip board 
Javascript :: html show password 
Javascript :: document.getanimation 
Javascript :: javascript name convention 
Javascript :: jquery if else click function 
Javascript :: javascript fetch 
Javascript :: count length of a string javascript 
Javascript :: npm md to html 
Javascript :: bresenham algorithm 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =