JSFiddle - React, Tailwind, and code Playground

JavaScript

var arr = [0,1,2];

function swapElements(a, x, y){
    var temp = a[x];
    a[x] = a[y];
    a[y] = temp;
}

console.log(arr);

swapElements(arr,0,1);

console.log(arr);