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 ...
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);
13:13
How to Use the Spread Operator in JavaScript - 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 ...
16:01
#44 What is the Spread Operator? | JavaScript Full Tutorial - YouTube
08:30
Rest parameters and Arguments | JavaScript - YouTube
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 - Its utility in a function call allows us to extract function parameters from an iterable. In this tutorial, we learn how to use Spread Syntax with arguments in JavaScript functions. A Spread operator, denoted with (...) followed by the name of the iterable expands the iterable into its constituent ...
Hexlet
hexlet.io โบ courses โบ js-functions โบ lessons โบ spread-operator โบ theory_unit
Spread syntax (unpacking arguments) | JS: Functions - Hexlet
April 29, 2025 - The spread statement in function calls is syntactically identical to the rest statement in definitions, but does the opposite. Let's take the sum() function as an example: const sum = (...numbers) => { let result = 0; for (let num of numbers) { result += num; } return result; }; Let's call sum() by applying the spread statement to an array of arguments:
GeeksforGeeks
geeksforgeeks.org โบ javascript-spread-operator
JavaScript Spread Operator | GeeksforGeeks
The spread operator (...) in JavaScript ... It is commonly used in situations where you want to copy or merge arrays, objects, or even pass arguments to functions.1....
Published ย November 11, 2024
JavaScript Tutorial
javascripttutorial.net โบ home โบ javascript array methods โบ javascript spread operator
The Practical Usages of JavaScript Spread Operator
May 8, 2024 - The spread operator (...) unpacks the elements of an iterable object. The rest parameter (...) packs the elements into an array. The rest parameters must be the last arguments of a function.
David Walsh
davidwalsh.name โบ spread-operator
6 Great Uses of the Spread Operator
February 1, 2017 - Thanks to ES6 and the likes of ... like JSX. I've become a big fan of the spread operator, three dots that may change the way you complete tasks within JavaScript. The following is a listing of my favorite uses of the spread operator within JavaScript! To this point we've called Function.prototype.apply, passing an array of arguments, to call a ...