青春有我
let students = [ { name:"张三", score:98 }, { name:"李四", score:65 }, { name:"王五", score:75 }];students.sort((a,b)=>{ return b.score-a.score;});输出:[ {name: "张三", score: 98}, {name: "王五", score: 75}, {name: "李四", score: 65}]更新//使用split("||")可以分割"||"两侧字符串,得到一个数组。数组第一项为姓名,第二项为分数//按分数排序score.sort((a,b)=>{ scoreA = +a.split("||")[1]; scoreB = +b.split("||")[1]; return scoreB - scoreA;});//输出姓名和分数for(var i = 0;i < score.length;i++){ //姓名 console.log(score[i].split("||")[0]); //分数 console.log(score[i].split("||")[1]);}这个问题其实挺基础的,提问前先百度吧~