swap values in array javascript in place 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: javascript swap array elements
var b = list[y];
list[y] = list[x];
list[x] = b;
// Since ES6
[a[0], a[1]] = [a[1], a[0]]
var b = list[y];
list[y] = list[x];
list[x] = b;