Lets say I have an array of objects[] and an array of numbers.
let objects = [
{name: apple, id:1},
{name: banana, id:2},
{name: orange, id:5}
];
let numbers = [5, 1];
I want to filter the object array, so only the id that matches with the numbers stays, and the order should be changed to match the numbers array.
result should be [{name: orange, id:5} , {name: apple, id:1} ]
Can I do it with javascript object prototypes? or can I use 3rd party tools like lodash ?
I've tried with code bellow, but it keeps the order of the original list:
result = object.filter(p => {
return numbers.includes(parseInt(p.id));
});