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