js中打乱数组 临时记下别人优秀的方法 function randomsort(a, b) { return Math.random() > .5 ? -1 : 1; //用Math.random()函数生成0~1之间的随机数与0.5比较,返回-1或1 } let arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; arr.sort(randomsort) console.log(arr.sort(randomsort));