ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
**数组排序** sort() 方法以字母顺序对数组进行排序: ``` var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.sort(); // 对 fruits 中的元素进行排序 ``` ***** **反转数组** reverse() 方法反转数组中的元素: ``` var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.sort(); // 对 fruits 中的元素进行排序 fruits.reverse(); ``` ***** **数字排序** ``` var points = [40, 100, 1, 5, 25, 10]; points.sort(function(a, b){ return a - b //正数为升序 }); console.log(points) ``` ``` var points = [40, 100, 1, 5, 25, 10]; points.sort(function(a, b){ return b - a //降序 }); console.log(points) ``` ``` var points = [{ id: 100, name: 'a' }, { id: 60, name: 'a' }, { id: 50, name: 'a' }]; function sortFunc() { points.sort(function (a, b) { return a.id - b.id }); console.log(points) } ```