所以我有一个如下所示的“结构”,我需要按照下面的“关键值”的顺序对其进行排序,以获得下面的“输出”。我怎样才能做到这一点?
结构体:
[
{
rs: {
1 MONTHS: "100",
1 YEAR: "200",
3 MONTHS: "30",
6 MONTHS: "400"}
},
{
rs: {
1 MONTHS: "500",
1 YEAR: "40",
3 MONTHS: "700",
6 MONTHS: "800"}
},
{
rs: {
1 MONTHS: "199",
1 YEAR: "1989",
3 MONTHS: "597",
6 MONTHS: "20"}
},
{
rs: {
1 MONTHS: "356",
1 YEAR: "10",
3 MONTHS: "877",
6 MONTHS: "1145"}
}
]
关键价值观:
["10", "20", "30", "40"]
排序后的输出
[
{
rs: {
1 MONTHS: "356",
1 YEAR: "10",
3 MONTHS: "877",
6 MONTHS: "1145"}
},
{
rs: {
1 MONTHS: "199",
1 YEAR: "1989",
3 MONTHS: "597",
6 MONTHS: "20"}
},
{
rs: {
1 MONTHS: "100",
1 YEAR: "200",
3 MONTHS: "30",
6 MONTHS: "400"}
},
{
rs: {
1 MONTHS: "500",
1 YEAR: "40",
3 MONTHS: "700",
6 MONTHS: "800"}
}
]
我想过滤我从 API 端点接收的数据结构格式,以根据值对其进行排序,使其与生成的键数组的顺序相同。
LEATH
相关分类