I have an object with the following structure:
let obj = {
"foo": ["orange", "apple", "pear", "grape", "lime"],
"bar": [12, 6, 18, 3, 22],
"bat": ["a", "b", "c", "d", "e"]
};
I want to sort by bar but also retain the order of foo and bat relative to bar, like so:
obj = {
"foo": ["grape", "apple", "orange", "pear", "lime"],
"bar": [3, 6, 12, 18, 22],
"bat": ["d", "b", "a", "c", "e"]
};
Is there a tidy way to do this, or do I need to convert it to an array of arrays, sort by index (e.g., arr.sort((a,b) => a[1] - b[1]);), and convert back to the object?