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

hibernate - How to load global settings frequently used in application in Java -

objective c - Ownership modifiers with manual reference counting -

python 3.x - Mapping specific letters onto a list of words -