How to sort using JS

the details are as follows
Zhang San"s score is 98, Li Si"s score is 65, Wang Wu"s score is 75
how to sort by score and show his score and name. Could you tell me how to sort from high to low with JS? Thank you very much.

Feb.28,2021

let students = [
    {
        name:"",
        score:98
    },
    {
        name:"",
        score:65
    },
    {
        name:"",
        score:75
    }
];
students.sort((a,b)=>{
    return b.score-a.score;
});

output:

[
    {name: "", score: 98},
    {name: "", score: 75},
    {name: "", score: 65}
]
< H2 > Update < / H2 >
//split("||")"||"
//
score.sort((a,b)=>{
    scoreA = +a.split("||")[1];
    scoreB = +b.split("||")[1];
    return scoreB - scoreA;
});

//
for(var i = 0;i < score.length;iPP){
    //
    console.log(score[i].split("||")[0]);
    //
    console.log(score[i].split("||")[1]);
}

this question is actually quite basic. Let's start with Baidu before asking questions.


arrays are sorted by sort. Depending on your data format, determine what's best to do


arr.sort((a,b)=>{
    return b-a
})

study while reading


var testList=[......]
function sortList(a, b) {
    return b.score - a.score
}
testList.sort(sortList)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e5a880-66f5e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e5a880-66f5e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?