sort
Sort the elements in an array.
list.sort([compareFunction])
sort
sorts the elements in place and returns the sorted array. The API is the same as the native sort API.
import { observe } from "can/everything";
const names = new observe.Array(['Chris', 'Alice', 'Bob']);
names.sort((a, b) => {
if (a.name < b.name) {
return -1;
} else if (a.name > b.name) {
return 1;
} else {
return 0;
}
});
console.log(names); //-> ['Alice', 'Bob', 'Chris']
Parameters
- compareFunction
{function(a, b)}
:Specifies a function that defines the sort order.
Events
sort
causes length events to be fired.