lodash sortby multiple fields desc and asc

Spread the love

Lodash sortby multiple fields desc and asc

//ascending

var data = [{
name: ‘ravi’,
age: 23
}, {
name: ‘john’,
age: 12
}, {
name: ‘kavi’,
age: 51
}, {
name: ‘rose’,
age:33
}];

let result = _.orderBy(data, [‘name’, ‘age’],
[‘asc’, ‘asc’]);

console.log(‘result ‘, result);

 

//decending

var data = [{
name: ‘ravi’,
age: 23
}, {
name: ‘john’,
age: 12
}, {
name: ‘kavi’,
age: 51
}, {
name: ‘rose’,
age:33
}];

let result = _.orderBy(data, [‘name’, ‘age’],
[‘desc’, ‘desc’]);

console.log(‘result ‘, result);

 

 

admin

admin

Leave a Reply

Your email address will not be published.