I had some code that looked something like this:
To my surprise the resulting output of the console logging was identical. Both output the array in the same order. So what’s going on here?
As it turns out, the reverse method actually mutates the original array. Obviously if you don’t know this (like I didn’t), this can be problematic. The best way around this shorting coming is to spread the array into a new one, then reverse it like this: