【发布时间】:2020-07-25 18:19:49
【问题描述】:
假设我有一个对象数组:
let array = [
{id: 0, type: "Office" },
{id: 1, type: "Security" },
{id: 2, type: "Office" },
{id: 3, type: "Security" },
{id: 4, type: "Security" },
{id: 5, type: "Office" },
{id: 6, type: "Agent" },
{id: 7, type: "Security" }
];
我需要根据自定义的分类序列集进行排序,即["Office", "Agent", "Security"] 得到以下输出:
var array = [
{id: 0, type: "Office" },
{id: 2, type: "Office" },
{id: 5, type: "Office" },
{id: 6, type: "Agent" }
{id: 1, type: "Security" },
{id: 3, type: "Security" },
{id: 4, type: "Security" },
{id: 7, type: "Security" }
];
没有找到任何合适的解决方案。
【问题讨论】:
标签: javascript sorting object categories