Documentation
swapAt

swapAt

Returns a copy of the array with the elements at the given indices swapped.

import { arr } from "@tsly/arr";
 
const fruit = ["apple", "banana", "pear"];
 
console.log(arr(fruit).swapAt(1, 2).take()); 
// ['apple', 'pear', 'banana']

Edit on CodeSandbox (opens in a new tab)