📜  对 json 进行降序排序 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:50.400000             🧑  作者: Mango

代码示例1
const data = [
    {id: 1, name: "Bob", email: "example@email.com"},
    {id: 2, name: "Tom", email: "example@email.com"},
    {id: 3, name: "Cat", email: "example@email.com"},
    {id: 4, name: "Mat", email: "example@email.com"},
    {id: 5, name: "Tim", email: "example@email.com"},
];

let sortedData = data.slice().sort((a, b) => b.id - a.id);
console.log(sortedData);