There is a bit of a joke in the land of JavaScript that arrays have one too many functions with scarily similar names. You may have seen this tweet...
For further actions, you may consider blocking this person and/or reporting abuse
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/
So glad it helped! Sorry it came a little late 😅
It's perfect. Thaaaaanks.
Always have to look up which one I want too!
Which one mutated again? .splice? .slice?
In a similar vein of mild frustration:
I hate the person that made .substring and .substr happen. They are similar, but not quite. But the name is SO similar.
What's the difference between
.shift()
and.pop()
?Pop() removes an item from the end of the array and shift() removes an item from the beginning of it.