I am trying to sort the below array, based on multiple values, report_yr and report_qtr, the array should be sorted according to year first and then as per quarter(for that same year).
// input array
let arr = [{
report_yr: '2008',
report_qtr: '1'
},
{
report_yr: '2019',
report_qtr: '3'
},
{
report_yr: '2019',
report_qtr: '4'
},
{
report_yr: '2017',
report_qtr: '2'
},
{ report_yr: '2008',
report_qtr: '2'
}];
// expected output:
[
{ report_yr: '2019',
report_qtr: '4' },
{ report_yr: '2019',
report_qtr: '3' },
{ report_yr: '2008',
report_qtr: '1'
},{ report_yr: '2008',
report_qtr: '2'
},
{ report_yr: '2017',
report_qtr: '2' } ];
// What I am trying:
I am trying to use loadash methods for this,
_.sortBy(arr,
['report_yr', 'report_qtr']);
Similarly tried with orderBy but no luck so far.
report_qtrwhenreport_yris2018but when the objects withreport_yrare2019the objects descend?