javascript - Array sorting. Where do the arguments come from? -


where arguments , b come in sorting function? passed automatically?

dir = "asc" sortarray = new array("hello", "link google", "zfile", "afile");  //sort array if (dir == "asc") {     sortarray.sort(function(a, b) {         return a.tolowercase() > b.tolowercase()     }); } else {     sortarray.sort(function(a, b) {         return b.tolowercase() > a.tolowercase()     }); }      (var = 0; < sortarray.length; i++) {     console.log(sortarray[i]); } 

are passed automatically?

yes.

you creating anonymous comparator function, sort function calls whenever needs compare 2 objects.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -