swap two consecutive array item javascript code example
Example 1: how to swap two elements in an array js
// Since ES6
[a[0], a[1]] = [a[1], a[0]]
Example 2: how to swap two elements in an array javascript
// Before ES6
const temp = a[x]; // NOT RECOMMENDED UNLESS COMPLETELY UNAVOIDABLE
a[x] = a[y];
a[y] = temp;