Here is a tutorial on how to use the spread operator:
What is the function of the Spread Operator: clone a data but do not affect the original data
1./Copy 1 array
for an array let arr=[1,2,3,4]; To copy the normal array arr, we do the following let copy =arr
if you are missing the … in the array, what will happen:
2./ join 2 arrays together (Concatenate arrays)
To join any two arrays together in JavaScript, we have a way like using function concat(), code
result if using spread operation : result
We see the two results are the same.
Copy an object
To copy an object in the usual way, what will we use?
don’t forget the sign … if you forget, the data will be
Merge objects together
To concatenate 2 or more objects together, we will use the function object.assign() to do it as follows:
note: when using Spread Operator : what data is … that data
you have array you use for array, you have obj you use for obj can’t attach obj to arr like the example below