给定一个对象数组:
{ key: "a",value: 42 },{ key: "d",value: 28 },{ key: "c",value: 92 },{ key: "b",value: 87 }
和一组键:
["c","a","b","d"]
是否有一个ECMAScript函数或第三方JavaScript库,让您可以在一行/函数调用中排序第一个对象数组,以匹配第二个数组中指定的键的顺序,以使结果为:
{ key: "c",{ key: "a",value: 87 },value: 28 }
提供功能或算法的其他问题:
> Javascript – sort array based on another array – Stack Overflow
> javascript – How do I sort an array of objects based on the ordering of another array? – Stack Overflow
类似/相关问题:
> Sorting an Array of Objects in PHP In a Specific Order
> php – Sort array of objects