1 回答
TA贡献1998条经验 获得超6个赞
您可以使用.sort:
const chart = [
{
"Nov 24, 2020": {
"a": 1,
"b": 0,
"c": 0,
"unix_start": 1606194000,
"unix_end": 1606280400
}
},
{
"Nov 23, 2020": {
"a": 0,
"b": 2,
"c": 1,
"unix_start": 1606107600,
"unix_end": 1606194000
}
},
{
"Nov 22, 2020": {
"a": 0,
"b": 0,
"c": 0,
"unix_start": 1606021200,
"unix_end": 1606107600
}
},
]
const sortedArray = chart.sort((a,b) => {
const [valueOfA] = Object.values(a);
const [valueOfB] = Object.values(b);
return valueOfA.unix_start - valueOfB.unix_start;
});
console.log(sortedArray);
添加回答
举报