Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Why would you copy an array like this, rather than
let copy = arr
?Because of it being a shallow copy.
The spread operator would mean this
However, this only works for flattened arrays. Multidimensional arrays will be deep copies at only the top level.
Thank you for explaining! :)
It does a deep copy for an array only, but does a shallow copy when used on an object. Is that right? Doesn't mention it in your article
That is correct. And yes, it's something that I likely should have mentioned!