Introduction to the use of the sort of method for arrays in javascript
<html><head><title> An array of sort() methods </title><script>var arr = [2,4,8,1,22,3];var arrSort= arr.sort();//Not properly sorted, the array is converted to a string and then sorteddocument.write(" The default sort array is: " + arrSort);//1,2,22,3,4,8document.write("<br/>");//The comparison functionfunction mysort(a,b){return a-b;}var arrSort2 = arr.sort(mysort);// The incoming The comparison functiondocument.write(" The array of comparison parameters passed in is: " + arrSort2);//The correct orderdocument.write("<br/>");document.write(" The original array is: " + arr);</script></head><body><div id="time"></div></body></html>