gpt4 book ai didi

javascript - 如何根据具有不同排序顺序的多个值对 json 对象进行排序

转载 作者:搜寻专家 更新时间:2023-11-01 04:36:34 25 4
gpt4 key购买 nike

<分区>

我有以下 JSON 对象

   var data1 =  [
{id: "1", name: "b", lastname: "y", marks: "10"},
{id: "1", name: "a", lastname: "x", marks: "20"},
{id: "2", name: "a", lastname: "x", marks: "30"},
{id: "2", name: "b", lastname: "x", marks: "40"},
{id: "2", name: "c", lastname: "z", marks: "60"},
{id: "3", name: "d", lastname: "x", marks: "50"},
{id: "3", name: "a", lastname: "c", marks: "70"}
];

我要根据不同的条件对这个对象进行排序,比如-

先按名字升序排序

按姓氏降序排序结果

比按降序标记排序结果

字段及其订单类型由网页动态生成。

*** 这里排序字段,它们的类型不固定,可能是 name asc、marks asc、lastname desc 或 marks desc、lastname desc、name asc 之类的东西

任何人都可以帮我推荐任何 jquery、java 脚本插件或函数吗?

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com