Swap JavaScript Array Items Inline
Today while doing an Exercism, I learned that through ES6 destructuring we can swap two array items in one line of code. Here's how it works:
[array[0], array[1]] = [array[1], array[0]]
Items one and two are swapped in array
. Modify those values in-place like a boss.