Looking to filter a JSON Object (Array of Arrays) with a specific order requirement:
order: ['Hors','TTC','Total général', 'verger', ' Tra']
data = [[" Tra", "100 - 149 ch", "Total"]
[" Tra", "150 - 199 ch", "150 - 159 ch"]
[" Tra", "150 - 199 ch", "160 - 169 ch"]
[" Tra", "500 - 999 ch", "Total"]
[" Tra", "Total", ""]
["Comparable", "", ""]
["Hors", "", ""]
["TTC", "", ""]
["Total général", "", ""]
["vergers", " 1 - 49 ch", "20 - 29 ch"]
["vergers", " 1 - 49 ch", "30 - 39 ch"]
["vergers", " 1 - 49 ch", "40 - 49 ch"]
["vergers", " 50 - 99 ch", "70 - 79 ch"]]
Attempts using sort() method have not met the criteria due to spaces within strings:
data.sort(function (a, b) {
return data.sort((a,b) => order.indexOf(a) - order.indexOf(b)) ;
});
Despite efforts, this approach did not yield the desired outcome, retaining the same Object structure.