swap two items in array ecmascript 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: swap elements in array typescript
[elements[0], elements[3]] = [elements[3], elements[0]];
// Since ES6
[a[0], a[1]] = [a[1], a[0]]
[elements[0], elements[3]] = [elements[3], elements[0]];