数组依靠 内部变量重新排序
var numbers = [
{
id: 1,
sort: 2
}, {
id: 2,
sort: 4
}, {
id: 3,
sort: 1
}, {
id: 4,
sort: 1
}, {
id: 5,
sort: 66
}, {
id: 6,
sort: 8
}, {
id: 7,
sort: 3
},
];
numbers.sort(function (a, b) {
return b.sort - a.sort;
});
console.log(numbers);
以下为打印值
[
{ id: 5, sort: 66 },
{ id: 6, sort: 8 },
{ id: 2, sort: 4 },
{ id: 7, sort: 3 },
{ id: 1, sort: 2 },
{ id: 3, sort: 1 },
{ id: 4, sort: 1 }
]
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。