Categories
JavaScript Answers

How to use Lodash to sort array of object by value with JavaScript?

Spread the love

To use Lodash to sort array of object by value with JavaScript, we use the orderBy method.

For instance, we write

const sortedChars = _.orderBy(chars, ["name"], ["asc"]);

to call orderBy to sort the chars array by the name property of each object in chars.

We use ['asc'] to specify that we sort by ascending order.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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