const newData = [
{
id: 1,
score: 88,
},
{
id: 1,
score: 53,
},
{
id: 1,
score: 41,
},
{
id: 1,
score: 43,
},
{
id: 1,
score: 91,
},
];
按数组元素score从大到小排列:
newData = newData.sort(function(a, b){return (a.score < b.score) ? 1 : -1});
const newData = [
{
id: 1,
score: 91,
},
{
id: 1,
score: 88,
},
{
id: 1,
score: 53,
},
{
id: 1,
score: 43,
},
{
id: 1,
score: 41,
},
];
按数组元素score从小到大排列:
newData = newData.sort(function(a, b){return (a.score > b.score) ? 1 : -1});
const newData = [
{
id: 1,
score: 41,
},
{
id: 1,
score: 43,
},
{
id: 1,
score: 53,
},
{
id: 1,
score: 88,
},
{
id: 1,
score: 91,
},
];