直接上例子
1.无参调用返回按unicode字符编码排序
var arr = [1,2,0,21,15,6,34,9,45];
var arrSort = arr.sort();
console.log(arrSort);//会返回[0,1,15,2,21,34,45,6,9]
2.有参调用,参数为匿名函数
var arr = [1,2,0,21,15,6,34,9,45];
var arrSort = arr.sort(function(a,b){return a-b});
console.log(arrSort);//会返回[0,1,2,6,9,15,21,34,45]
原文地址:https://www.cnblogs.com/wangxuxu7912/p/11371295.html
时间: 2024-10-08 04:26:11