看懂了数字的排序,没看懂字符串的怎么排序
如题,数字排序理解原理了,但是字符排序怎么判断顺序呢,拿课程中的例子举例:
<script type="text/javascript"> function sortNum(a,b) { return a - b; } var myarr = new Array("Hello","John","love","JavaScript"); document.write(myarr.sort(sortNum));
运行结果:
JavaScript,love,John,Hello