js 自定义数组排序和随机数组

var array = [1,2,5,3]
//随机打乱数组
array.sort(function(ls, rs){
if(Math.random() < 0.5) {
return -1;

}
else {
return 1;
}

})
console.log(array);

//数组排序
var array1 = [1,2,5,3]
array1.sort(function(lhs, rhs){
if(lhs < rhs) {
return -1;
}
else {
return 1;
}

})

console.log(array1);
原文地址:https://www.cnblogs.com/StevenChancxy/p/9220622.html