How to sort an array of objects in a specific order in JavaScript

We were trying to sort an array of objects which contains a status key which has “active”, “inactive”, “pending”. So we just wanted to sort the array in such a way that all “active” records would appear on top followed by “pending” and then “inactive”.

Let’s consider the following array to sort by status.

Now we want to sort an array in the following order.

Use the following code to sort an array by statusOrder.

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *