You can also use rest parameters:
function Numbers(...numbers){
this.numbers = numbers;
}
Answer from madox2 on Stack OverflowMDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Spread_syntax
Spread syntax (...) - JavaScript - MDN Web Docs - Mozilla
May 22, 2026 - The spread (...) syntax allows an iterable, such as an array or string, to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected. In an object literal, the spread syntax enumerates the properties of an object and adds the key-value ...
Is there a way to set parameters for the "arguments" variable without using the spread operator?
coordinated repeat hobbies reach sense smell snails sophisticated act boat This post was mass deleted and anonymized with Redact More on reddit.com
Javascript Rest parameters
The rest parameter takes all the remaining parameters and passes them to the function as an array: function restTest(param1, param2, ...rest) { console.log(param1); console.log(param2); console.log(rest); } restTest(1, 2, 3); -> 1 2 [3] restTest(1, 2); -> 1 2 [] restTest(1, 2, 3, 4); -> 1 2 [3, 4] So in your case sum1([3, 2]) is equivalent to sum2(3, 2). More on reddit.com
Automatic assignment of parameters in class constructor with spread operator
There's no way to do this in TypeScript. Why do you want to use a class instead of just using the object as you get it? More on reddit.com
Best way to delete undefined values from an object
If you only want to remove the properties that are undefined, but null is ok, then use this: for (let key in person) { if(person[key] === undefined) { delete person[key] } } If you also want to remove properties that are null, then just remove the && person[key] !== null part. More on reddit.com
13:13
How to Use the Spread Operator in JavaScript - YouTube
08:06
JavaScript REST PARAMETERS in 8 minutes! 🗄 - YouTube
04:55
JavaScript SPREAD OPERATOR in 4 minutes! 📖 - YouTube
05:26
Spread Operator in JS | Simplified in 5 minutes - YouTube
01:40
How to pass parameters to function arguments using (...) spread ...
Top answer 1 of 4
9
You can also use rest parameters:
function Numbers(...numbers){
this.numbers = numbers;
}
2 of 4
3
Using a spread does the same thing cleaner in ES2015
this.numbers = [...arguments];
Just remember that this won't work in arrow functions (no arguments), and you're good. Rest arguments and Array.from are other options that are fine as well.
The old-fashioned ES5 is:
this.numbers = [].slice.call(arguments);
Codesmith Enterprise
codesmith.io › blog › perfecting-javascripts-spread-rest-and-default-parameters
Codesmith | Perfecting JavaScript's Spread, Rest, and Default Parameters
Spread syntax can be used when calling constructors that accept multiple arguments: We can easily convert a Set or a NodeList to an array: By combining Set and spread syntax , we can remove duplicates from an array: Strings are iterable, so we can spread them into arrays of characters: Rest parameters allow us to represent an indefinite number of arguments as an array.
TutorialsPoint
tutorialspoint.com › How-to-use-Spread-Syntax-with-arguments-in-JavaScript-functions
How to use Spread Syntax with arguments in JavaScript functions?
November 10, 2022 - It is most commonly used in function calls to expand the iterable at the time of parameter initialization. Here we are going to show the use of the spread operator in the function call. We will create an array of strings and pass it as a function argument for printing.
GeeksforGeeks
geeksforgeeks.org › javascript-spread-operator
JavaScript Spread Operator | GeeksforGeeks
The spread syntax is used for expanding an iterable in places where many arguments or elements are expected. It also allows us the privilege to obtain a list of parameters from an array. The spread syntax was introduced in ES6 JavaScript.
Published November 11, 2024
Programiz
programiz.com › javascript › spread-operator
JavaScript Spread Operator
The JavaScript spread operator (...) allows an iterable to be expanded in places where zero or more arguments or elements are expected. In this tutorial, you will learn about the JavaScript spread operator with the help of examples.
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › javascript spread operator
The Practical Usages of JavaScript Spread Operator
May 8, 2024 - const odd = [1,3,5]; const combined = [2,4,6, ...odd]; console.log(combined);Code language: JavaScript (javascript) ... In this example, the three dots ( ...) located in front of the odd array is the spread operator. The spread operator (...) unpacks the elements of the odd array. Note that ES6 also has the three dots ( ...) which is a rest parameter that collects all remaining arguments of a function into an array.