This operator (...
) helps you achieve many things that previously required many lines of code, unfamiliar syntax, and more.
The three dots operator has two different meanings in JavaScript. The syntax is very similar, but you use each one in different contexts. These two different uses of the ...
are the spread
and rest operators
const newArray = ['firstItem', ...oldArray];
Let's now look at various instances in which we can use the spread operator.
let studentNames = ["Daniel", "Jane", "Joe"]
let names = [...studentNames]
let user = { name: "John Doe", age: 10 };
let copiedUser = { ...user };
console.log(copiedUser); // { name: "John Doe", age: 10 }