DEV Community

Discussion on: Splice! Slice! Shoot, I meant Shift!

Collapse
 
jjlabajo profile image
JJ Labajo • Edited

I had this experience when I was just beginning to understand javascript, at the same time I was exploring Vue. I got into situation where I assigned a variable to a spliced array, and I was so dumb wondering why does both arrays are changing even if I just manipulated one of them.

I was googling for answers but I wasn't able to see a solution - soooo I ended up using Json Stringify and Parse. When I assign the array to a variable, I, first, Stringify it and then Parse it (just to make a "shallow" copy). Yea, funny right? Months later I accidentally found out the solution of the problem while reading some article. That "months later" is today, and the "article" is yours. Thanks a lot. .slice() FTW! \m/

Collapse
 
laurieontech profile image
Laurie

So glad it helped! Sorry it came a little late 😅

Collapse
 
jjlabajo profile image
JJ Labajo

It's perfect. Thaaaaanks.