如何基于id对此数组进行排序?
const arr = [{
"id": 38938888,
"subInternalUpdates": true,
},
{
"id": 38938887,
"subInternalUpdates": true
},
{
"id": 38938889,
"subInternalUpdates": true
}
];
const sorted_by_name = arr.sort((a, b) => a.id > b.id);
console.log(sorted_by_name);
预期输出
const arr = [
{
"id": 38938887,
"subInternalUpdates": true
},
{
"id": 38938888,
"subInternalUpdates": true,
},
{
"id": 38938889,
"subInternalUpdates": true
}
];
a.id - b.id
代替。 - Bravo