The problem is this:
I have a array
of objects, which have properties id
and orden
(both integers). This array
I must order it taking into account the property orden
, depending on the order of the values that are in another array
of integers.
For example, if I have the following% co_of% of objects:
objs = [
{ order: 1, id: 121 },
{ order: 2, id: 122 },
{ order: 3, id: 123 },
{ order: 4, id: 124 },
{ order: 5, id: 125 },
]
And a array
with the values of the desired order:
orden = [5, 3, 2, 4, 1]
The result of ordering the first array
should be:
objs = [
{ order: 5, id: 125 },
{ order: 3, id: 123 },
{ order: 2, id: 122 },
{ order: 4, id: 124 },
{ order: 1, id: 121 },
]
This is the code to show the elements of array
array
:
orden.forEach((el, i) => {
console.log(el);
});