Languages

JavaScript - sorting array of objects in specific order (using existing lodash function)

0 points
Asked by:
JoanneSenior
1070

How can I sort array of objects in a specific, custom order?

I have the following array:

and I want it to be sorted in the following order by key value:

so the result would be:

How can I do this?

1 answer
0 points
Answered by:
Admin Dirask Community
4380

You can do it simply using lodash.

Practical examples

1. Full running example using lodash cdn:

2. Working with Node.js:

 

References

  1. Lodash Documentation - _.sortBy()
  2. Lodash Documentation - _.indexOf()
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join