I have an array of objects and I have array of numbers and I want objects to be arranged as per numbers in array. Using lodash sortby I tried to get desired result but that didn't work.
Here is what I tried
import * as _ from 'lodash';
let keys = [ '10001', '10002', '10004' ];
let c = [
{
name: 'John',
id: 10004,
},
{
name: 'Alice',
id: 10001,
},
{
name: 'Bob',
id: 10002,
is_app: 1,
},
]
const result = _.sortBy(c,keys);
// this is still printing original array
This is what I expect it to print
[
{
name: 'Alice',
id: 10001,
},
{
name: 'Bob',
id: 10002,
},
{
name: 'John',
id: 10004,
}
]
Any help or suggestion how to do this will be of great help:)