What is spread operator in Javascript ?
Spread Operator allows you to spread out the elements of an iterable object such as Array.
Syntax : [ ... Array ]
When to use spread operator ?
Suppose you have a array and you want to clone it.
let x = [1,2,3,4,5];
let y = x;
The above code is not cloning , x sets a reference to y , if the value of x gets changed the the value of y will also get changed.
There are many ways to can clone array in javascript
let x = [1,2,3,4,5];
let y = Object.assign([],x);
console.log(y);
//Output : [1,2,3,4,5]
Source : https://codelearningpoint.com/
Top comments (0)