// Since ES6
[a[0], a[1]] = [a[1], a[0]]
// How to swap two array elements in JavaScript
const arr = ['a', 'b', 'c', 'e', 'd'];
[arr[1], arr[0]] = [arr[0], arr[1]]
console.log(arr);
// Output:
// [ 'b', 'a', 'c', 'e', 'd' ]
// Before ES6
const temp = a[x]; // NOT RECOMMENDED UNLESS COMPLETELY UNAVOIDABLE
a[x] = a[y];
a[y] = temp;
var b = list[y];
list[y] = list[x];
list[x] = b;