I have a javascript object containing an array of other objects, like the following:
const myObj = {
people: [{
firstname: 'Dave',
lastName: 'Jones',
sortOrder: 22
},
{
firstname: 'Jane',
lastName: 'Smith',
sortOrder: 11
}
],
otherPeople: [{
firstname: 'Jen',
lastName: 'SomeLastName',
sortOrder: 33
},
{
firstname: 'ExampleFirstName',
lastName: 'ExampleLastName',
sortOrder: 12
}
]
};
What I’m trying to do is, given a certain number, let’s say 2, remove that amount of sub objects with the highest sortOrder.
So if I were to eliminate 2, the new object would look like the following:
const myObj = {
people: [{
firstname: 'Jane',
lastName: 'Smith',
sortOrder: 11
}
],
otherPeople: [{
firstname: 'ExampleFirstName',
lastName: 'ExampleLastName',
sortOrder: 12
}
]
};
Is there a best way to do this?
Thanks!