JavaScript排序对象中的对象数组中的对象中的字段
我的javascript不太熟练,我需要根据描述对数组进行排序的问题。我看了几个主题,但我试图对其进行排序,但是到目前为止没有运气。
我有一系列看起来像这样的对象:
{
category: null,
code: "GGG",
id: 3,
description: "Gama"
},
{
category: null,
code: "AAA",
id: 1,
description: "Alfa"
},
{
category: null,
code: "BBB",
id: 2,
description: "Beta"
}
此数组由一个函数返回:
return refort.data
因此,想根据上升顺序的描述对结果集进行排序,这意味着我的列表在返回后看起来像这样:“ alfa”,“ beta”,“ gama”。
我试图使用排序函数:
return result.data.sort(); ,
但这对我没有帮助。
I'm not very skilled with JavaScript and I have an issue where I need to sort array based on description. I looked several topics and I have tried to sort it but so far no luck..
I have an array of objects that looks like this:
{
category: null,
code: "GGG",
id: 3,
description: "Gama"
},
{
category: null,
code: "AAA",
id: 1,
description: "Alfa"
},
{
category: null,
code: "BBB",
id: 2,
description: "Beta"
}
And this array is returned by a function that says:
return result.data
So want to sort that result set based on description on ascending order, which means my list would look like this after the return: "Alfa", "Beta", "Gama".
I was trying to use sort function:
return result.data.sort();
But that didn't help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做:
You can do: