DEV Community

Discussion on: Deep vs Shallow Copy - with Examples

 
laurieontech profile image
Laurie

So this is what I see

let arr = [1,2,3]
> arr[5] = 1
> arr.slice()
[ 1, 2, 3, <2 empty items>, 1 ]
> [...arr]
[ 1, 2, 3, undefined, undefined, 1 ]

But no docs are telling me why that's the case. Still searching because I genuinely want to know!

Thread Thread
 
laurieontech profile image
Laurie • Edited

So the difference is holes in an array versus undefined elements. And that happens due to this:

Also explained this way:

Thread Thread
 
juliang profile image
Julian Garamendy

Awesome! Thank you!