I have two arrays which are parallel together (I don't know if it's the right term in English!). I mean the index 0 or 1 or ... of the first array represents the same index in the second one and vise versa...
Now I know how to sort the portionDurations
array (one the arrays we have) based on start
value like this:
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);
Apparently this sorting may change the order of the portionDurations
array while no change is done to portionArrayEn
array. But we need to keep portionArrayEn
in parallel. How can I do this?