// 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;
var a = [1,2,3,4,5], b=a.length;
for (var i=0; i<b; i++) {
a.unshift(a.splice(1+i,1).shift());
}
a.shift();
//a = [5,4,3,2,1];