I have the following array:
const result = [
[{value: 123, parentID: 1}, {value: 'string123', parentID: 2}],
[{value: 54764, parentID: 1}, {value: 'string321', parentID: 2}],
[{value: 321, parentID: 1}, {value: 'string565632', parentID: 2}],
]
and I need to sort this, multidimensional array based on the value, but which object to select is based on parentID.
What I have tried so far:
const parentID = 1;
const sortedResult = result.filter((row) => {
const selectedColumn = row.find((column) => column.parentID === parentID));
return _.orderBy(selectedColumn, ['value'], ['asc']);
});
but this isn't working, any ideas what could?
Desired output would be:
[
[{value: 123, parentID: 1}, {value: 'string123', parentID: 2}],
[{value: 321, parentID: 1}, {value: 'string565632', parentID: 2}],
[{value: 54764, parentID: 1}, {value: 'string321', parentID: 2}],
]
valueproperty and aparentIDproperty. In order to choose by which object to sort, you would useparentID.