Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

the rest operator javascript

function sum(...numbers) {
	return numbers.reduce((accumulator, current) => {
		return accumulator += current;
	});
};
 
sum(1,2) // 3
sum(1,2,3,4,5) // 15
Comment

javascript rest

function sum(...numbers) {
    console.log(numbers); // [1, 2, 3]
    return numbers.reduce((a, b) => a + b, 0);
}

console.log(sum(1, 2, 3)); // 6
console.log(sum(3, 2));    // 5
console.log(sum());        // 0
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript atan2 
Javascript :: electron in webpack 
Javascript :: javascript for each 
Javascript :: multiple forms formData js 
Javascript :: adding event listener to multiple elements 
Javascript :: create multiple buttons in javascript 
Javascript :: javascript get first element of array 
Javascript :: remove duplicates in json in flutter 
Javascript :: set number of reducers in mapreduce 
Javascript :: array last element 
Javascript :: anagram javascript 
Javascript :: js filter text 
Javascript :: js reading file 
Javascript :: js delete all from array 
Javascript :: ajax call to load a page on scrolling 
Javascript :: link external file by url using javascript 
Javascript :: parallax using npm parallax 
Javascript :: jquery save method 
Javascript :: js for i in html collection 
Javascript :: javascript entries() method 
Javascript :: decode jwt token without library 
Javascript :: iterate table in jquery 
Javascript :: check if something is a letter in js 
Javascript :: jsx react 
Javascript :: how to draw a long underline in react native 
Javascript :: react paypal express checkout 
Javascript :: reset reactive state vue 3 
Javascript :: listen to localstorage changes 
Javascript :: iframe content zoom in and zoom out jquery 
Javascript :: Discord.js v13 / command handler 
ADD CONTENT
Topic
Content
Source link
Name
5+8 =