I already read the previous questions answered, but it didn't fit with my need.
I have an array of objects such as
var Widgets = [
[{Id: 'abcdef', post_id: 12345}],
[{Id: 'ghijkl', post_id: 45678}],
[{Id: 'mnoptq', post_id: 90123}]
];
I have a second array :
var sortArray = ['ghijkl', 'mnoptq', 'abcdef'];
I need To reorder Widgets with the initial order of elements which appears on sortArray
i've succeed to do it this way
sortArray.forEach(function(Id) {
var found = false;
Widgets = Widgets.filter(function(Widget) {
if(!found && Widget.Id == Id) {
NewWidgets.push(Widget);
found = true;
return false;
} else {
return true;
}
});
});
But I wish to improve this code by using _SortBy but I didn't succeed so far...
Anyhelp ?
Edit
Final result should be
var Widgets = [
[{Id: 'ghijkl', post_id: 45678}],
[{Id: 'mnoptq', post_id: 90123}],
[{Id: 'abcdef', post_id: 12345}]
];