swap to elements in list 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: exchange value between 2 items in array javascript
var a = 1;
var b = 2;
[a,b] = [b,a];
// Since ES6
[a[0], a[1]] = [a[1], a[0]]
var a = 1;
var b = 2;
[a,b] = [b,a];