DEV Community

Discussion on: 5 Uses for the Spread Operator

Collapse
 
deleteman123 profile image
Fernando Doglio

Nice quick round up! Thanks! A quick word of warning, when copying an array, it does a shallow copy, so doing:

let myarr = [[1],[2]]
let copyArr = [..myarr]
copyArr[0][0] = 12

This will change myarr as well.

Collapse
 
laurieontech profile image
Laurie

Definitely. My understanding is that this only applies because the example above is multidimensional. So the first level is copied, but the deeper levels are referenced. If it's one-dimensional it is a deep copy.