Skip to main content
1 of 3
vatevr
  • 81
  • 1
  • 5

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;
});
vatevr
  • 81
  • 1
  • 5