Javascript Property with three dots (...)
Solution 1:
That is not ES6 but has only been added in ECMAScript 2018.
It is called "Object Rest/Spread Properties" and is part of the Spread Syntax.
Solution 2:
The [...something]
is the spread operator. It in essence allows for an array or string to be expanded. You will see it used often in React, but has many other use cases.
MDN has great documentation on the spread operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator
Solution 3:
...
(three dots in Javascript) is called the Spread Syntax or Spread Operator. This allows an iterable such as an array expression or string to be expanded or an object expression to be expanded wherever placed.
I want to list down the mostly used practical Use Cases of the Spread Syntax (Spread Operator). The following has been explained with examples in this stackoverflow answer.
- Combine Arrays (Concatenate Arrays)
- Copying Arrays
- Calling Functions without Apply
- Destructuring Arrays
- Function Arguments as Rest Parameters
- Using Math Functions
- Combining Two Objects
- Separate a String into Separate Characters