Try the solutions standard library offers you first.
Arrays in javascript could be sorted by using array.sort()
which additionally accepts a comparer predicate
sort((a, b) => a.name > b.name ? 1 : 0-1)
or alternatively
sort(function(a, b) {
if (a.name > b.name) {
return 1;
}
if (a.name < b.name) {
return -1;
}
return 0;
});