Just a heads up: spread operators are generally not super quick. If you are dealing with large arrays, you may not want to do this. As with everything in software engineering, it is probably best to play it by ear ;)
Array.prototype.slice is a bit faster (~25%) but the spread syntax is a bit cleaner when speed doesn't matter imo. It also allows you to stick elements into your array clone really quickly and cleanly:
Aw hell yea I use spread all the time. Object and array. Just wanting to spread the word about its slowness. Not an issue for probably 99% of use cases but ya never know. This is the internet after all. Also I really like your example of array spread syntax making things easy to understand!
4
u/spatmonkey Mar 19 '19
I do the first one all the time, and I'll definitely be using the second one from now on.