Let’s say we have an array and we need to swap to values. I am pretty sure that there are a lot of different solutions for this, but because here we have ES6, we can use array destructuring.
For example, our array looks like this:
const arr = [1, 2, 3, 4]
and if we want to swap second value with fourth, we can use this piece of code:
[arr, arr] = [arr, arr]
The only thing you have to remember is if you don’t use semicolons at all (like me, check Standard), in that case you have to put a semicolon in front of swap method, like this:
;[arr, arr] = [arr, arr]