re: 2 Ways to Merge Arrays in JavaScript VIEW POST


The "A. Using Spread" example fails to demonstrate the error, since it says return [...array1, array2] instead of return [...array1, ...array2] (it doesn't actually spread the string)
Instead it demonstrates the happy path of "immutably pushing" the string.

I firmly believe concat is dangerous and should only be used with arrays, not loose elements. Because your loose element will end up being an array someday, and you will SUFFER.
And on the other hand, it doesn't work on arraylikes:

[].concat([document.querySelector('body')],document.querySelectorAll('*')) // nope

;[document.querySelector('body'), ...document.querySelectorAll('*')] // yep

Oops, that’s a typo 😬 let me fix that 😰

code of conduct - report abuse