我有两个平行在一起的数组(我不知道这是否是英语中的正确术语!)。我的意思是第一个数组的索引 0 或 1 或 ... 表示第二个数组中的相同索引,反之亦然...
现在我知道如何根据 portionDurations
值对 start
数组(我们拥有的数组之一)进行排序,如下所示:
var portionArrayEn = ["olaf", "enjoying", "your", "new", "permafrost"];
var portionDurations= [
{ end: "9", start: "6" },
{ end: "4", start: "2" },
{ end: "8", start: "5.5"},
{ end: "5", start: "3" },
{ end: "6", start: "5" },
];
portionDurations.sort((a, b) => (a.start > b.start) ? 1 : -1);
console.log(portionDurations);
显然这种排序可能会改变 portionDurations
数组的顺序,而对 portionArrayEn
数组没有任何改变。但是我们需要保持 portionArrayEn
并行。我该怎么做?