0

I have an array of objects with the _id index

[{
    _id: 'zzz'
}, {
    _id: 'abc'
}, {
    _id: 'xxx'
}, {
    _id: '123'
}, {
    _id: 'several other objects not in the array'
}]

I also have an array like this

['abc', '123', 'xxx', 'zzz']

how can I make sure that the array of objects is correctly ordered by the array given?

I'm using 2 for loops but really looks ugly, and I'm sure there's a better way for this. thanks!

2
  • 2
    Another similar question that's useful: stackoverflow.com/questions/37671695/… (also answered by Nina Scholz 😉) Commented Nov 16, 2018 at 8:29
  • elegant, thank you Commented Nov 16, 2018 at 8:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.