ts实现将相同类型的数据通过排序放在一起

看下效果,可以将相同表名称的字段放在一起

排序适用于中英文、数字 

// 排序
function sortByType(items: any) {
  // 先按照类型进行排序
  items.sort((a: any, b: any) => {
    if (a.label < b.label) return -1;
    if (a.label > b.label) return 1;
    return 0;
  });

  return items;
}
// // 示例用法:
const items: Item[] = [
  { type: "哈哈" },
  { type: "第三方代发" },
  { type: "第三方代发" },
  { type: "哈哈" },
  { type: "蛋蛋蛋" },
  { type: "烦烦烦" },
  // more items
];

const sortedItems = sortByType(items);

相关推荐

  1. 2024/4/2 HarmonyOS学习笔记TS数据类型

    2024-07-12 03:30:04       32 阅读
  2. TS高级类型

    2024-07-12 03:30:04       52 阅读
  3. TS高级类型

    2024-07-12 03:30:04       26 阅读
  4. Rust :给数据类型一个别名

    2024-07-12 03:30:04       28 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-12 03:30:04       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-12 03:30:04       71 阅读
  3. 在Django里面运行非项目文件

    2024-07-12 03:30:04       58 阅读
  4. Python语言-面向对象

    2024-07-12 03:30:04       69 阅读

热门阅读

  1. linux:vi命令

    2024-07-12 03:30:04       17 阅读
  2. vagrant远程连接不上问题

    2024-07-12 03:30:04       18 阅读
  3. Android Gradle开发与应用(一): Gradle基础

    2024-07-12 03:30:04       22 阅读
  4. Android Gradle 开发与应用 (八): Gradle 与持续集成(CI)

    2024-07-12 03:30:04       22 阅读
  5. 宪法学学习笔记(个人向) Part.3

    2024-07-12 03:30:04       18 阅读
  6. 【Unity】RPG2D龙城纷争(十)战斗系统之角色战斗

    2024-07-12 03:30:04       22 阅读
  7. DP学习——策略模式

    2024-07-12 03:30:04       17 阅读
  8. UNIAPP 使用地图 百度 高德 腾讯地图路线轨迹

    2024-07-12 03:30:04       21 阅读
  9. 理解李彦宏的“不卷模型,卷应用”理念

    2024-07-12 03:30:04       23 阅读