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 :: delete cookie 
Javascript :: nodejs convert buffer to uint8array 
Javascript :: install video-react 
Javascript :: react native uid 
Javascript :: javascript xhr set parameters 
Javascript :: deploy nestjs app engine 
Javascript :: You might have more than one copy of React in the same app. 
Javascript :: How to scan a folder for documents with javascript 
Javascript :: react native notify user for new version of app 
Javascript :: js display 
Javascript :: geojson featurecollection 
Javascript :: filter the falsy values out of an array in a very simple way! 
Javascript :: how to give placeholder in input type date in angular 
Javascript :: dividing a number into digits javascript 
Javascript :: how a message persist in the localstorage in javascript 
Javascript :: react class component input text with clear button 
Javascript :: underline unused code vscode 
Javascript :: yup.array not working 
Javascript :: json schema e.g. 
Javascript :: javascript slider 
Javascript :: Javascript swap old and new method 
Javascript :: append a method to an already existing class in javascript 
Javascript :: make a if in jsx 
Javascript :: how to add author to javascript 
Javascript :: vue.js props undefined type 
Javascript :: vue js qr code scanner 
Javascript :: change node bash root 
Javascript :: document middleware in express 
Javascript :: vanilla js select by class 
Javascript :: history.back() and refresh in js 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =