I want to sort the javascript object in order of another object that have keys and sorting order
I have an object let say
sectionSorting = {
"metrics": "12",
"details": "3",
"portfolio": "5"
"backetst":"14"
}
I have another object like
sections = {
backtest: [{key: "abc", value: "xyz"}],
metrics: [{key: "abc", value: "xyz"}],
details: [{key: "abc", value: "xyz"}],
methodology: [{key: "abc", value: "xyz"}],
portfoolio: [{key: "abc", value: "xyz"}]
}
Now I want to sort the 'sections' object in the sorting order of 'sectionSorting' object. The feilds which do not have sorting order will remail in last.
The desired Output I need is,
sortedSections = {
details: [{key: "abc", value: "xyz"}],
portfoolio: [{key: "abc", value: "xyz"}],
metrics: [{key: "abc", value: "xyz"}],
backtest: [{key: "abc", value: "xyz"}],
methodology: [{key: "abc", value: "xyz"}],
}
I can not figure out how to do that Can Anybody help me ?