Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript sort callback

I need to sort a big list of Javascript items and I'm using the sort function like this:

var sorted_list = non_sorted.sort(function(a,b){
// Sort stuff here
});

What I'd like to do is to call a function when the sort function is done.

Is it possible to add a callback function to sort or to trigger an event when when sort is over?

like image 977
gyosko Avatar asked Dec 19 '22 23:12

gyosko


1 Answers

You are overcomplicating it. The sort method isn't asynchronous, so you don't need a callback or an event. Just put your code after the code that calls sort:

var sorted_list = non_sorted.sort(function(a,b){
  // comparer
});
// The code just continues here after the sort
like image 118
Guffa Avatar answered Jan 02 '23 13:01

Guffa