Exchanges the position of two elements in an array.
The target array.
The index of the first element to swap.
The index of the second elemento to swap.
The same target array.
const myarray = [0, 1, 2, 3, 4]PUtilsArray.swap(myarray, 1, 4)console.log(myarray) // 0, 4, 2, 3, 1 Copy
const myarray = [0, 1, 2, 3, 4]PUtilsArray.swap(myarray, 1, 4)console.log(myarray) // 0, 4, 2, 3, 1
Exchanges the position of two elements in an array.