Sort an array in Javascript/JQuery -


this question has answer here:

there array emails having few attributes to, from, subject, description. retrieve records database , populate rows in array. use access rows follows:

 (var = 0; < emails.length; i++) {     var = emails[i].to;     var sender = emails[i].sender;     var subject = emails[i].subject;     var description = emails[i].description;  } 

now need sort array alphabetically to values , store sorted emails in array sortedemails. how can in easiest possible way in javascript/jquery?

thanks.

arrays in javascript have sort function.

emails.sort(function(a, b) {     if (a.to < b.to) {      return -1;    } else {       return 1;    } } 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -