如何对多维数组进行多条件排序?
对 arr 数组同时按 "time" 字段和 "age" 字段进行降序排列
let arr = [
{
time: '2021-02-09',
data: [
{ name: 12, age: 10, id: 2001 },
{ name: 10, age: 11, id: 2010 },
{ name: 15, age: 34, id: 2008 },
{ name: 13, age: 20, id: 2008 },
]
},
{
time: '2021-02-01',
data: [
{ name: 12, age: 10, id: 2001 },
{ name: 10, age: 20, id: 2010 },
{ name: 15, age: 44, id: 2008 },
{ name: 13, age: 50, id: 2008 },
]
},
{
time: '2020-12-12',
data: [
{ name: 12, age: 11, id: 2001 },
{ name: 10, age: 50, id: 2010 },
{ name: 15, age: 09, id: 2008 },
{ name: 13, age: 18, id: 2008 },
]
},
{
time: '2021-06-07',
data: [
{ name: 12, age: 10, id: 2001 },
{ name: 10, age: 10, id: 2010 },
{ name: 15, age: 24, id: 2008 },
{ name: 13, age: 10, id: 2008 },
]
},
{
time: '2020-01-11',
data: [
{ name: 12, age: 10, id: 2001 },
{ name: 10, age: 10, id: 2010 },
{ name: 15, age: 24, id: 2008 },
{ name: 13, age: 10, id: 2008 },
]
},
]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
结果