I have an object that is being returned from a database like this: [{id:1},{id:2},{id:3}]
. I have another array which specified the order the first array should be
To my understanding, sorting is not necessary; at least in your example, the desired resulting array can be generated in linear time as follows.
var Result;
for ( var i = 0; i < Input.length; i++ )
{
Result[i] = Input[Order[i]-1];
}
Here Result
is the desired output, Input
is your first array and Order
the array containing the desired positions.