【发布时间】:2021-03-08 22:23:18
【问题描述】:
我有 2 个数组
a = [
{ label:"Price", value:10 },
{ label:"Active", value:false },
{ label:"Category", value:"food" },
{ label:"Remarks", value:"none" }
];
b = ["Active","Category","Price"];
如何根据 b 的顺序对 a 进行排序?我可以使用 ramda 吗?
像下面这样简洁的东西是理想的
R.sortBy(R.pipe(R.prop('label'), R.indexOf(R.__, a)))(b);
与这个问题类似,只是我没有索引,所以我不能使用 indexOf 方法。
Sort an array of objects based on another array of ids
感谢您的帮助!
【问题讨论】:
标签: javascript angular typescript sorting