To use _.sortBy()
function of lodash library in JavaScript, you need to follow these steps:
index.tsx29 chars2 lines
users
containing multiple objects as shown below:index.tsx128 chars7 lines
_.sortBy()
function to sort the array based on the property of an object. For example, to sort the array based on the age
property of an object, use the following code:index.tsx43 chars2 lines
This will return a new sorted array of users based on their age in ascending order.
index.tsx59 chars2 lines
This will return a new sorted array of users based on their age in descending order.
Note: The original array remains unchanged after using the sortBy()
function.
gistlibby LogSnag