我想使用一個字符串數組作爲模板如何排序其他數組。使用數組作爲排序順序
var sort = ["this","is","my","custom","order"];
,然後我要作爲排序依據由命令鍵(內容)對象的數組:
var myObjects = [
{"id":1,"content":"is"},
{"id":2,"content":"my"},
{"id":3,"content":"this"},
{"id":4,"content":"custom"},
{"id":5,"content":"order"}
];
,使我的結果是:
sortedObject = [
{"id":3,"content":"this"},
{"id":1,"content":"is"},
{"id":2,"content":"my"},
{"id":4,"content":"custom"},
{"id":5,"content":"order"}
];
怎麼會我那樣做?