toSorted
Copies and sorts the array.
Parameters
compareFn
Function used to determine the order of the elements. It is expected to return a negative value if the first argument is less than the second argument, zero if they're equal, and a positive value otherwise. If omitted, the elements are sorted in ascending order.
const myNums = Int32Array<Buffer>.from([11, 2, -22, 1]);
myNums.toSorted((a, b) => a - b) // Int32Array<Buffer>(4) [-22, 1, 2, 11]
Content copied to clipboard