I have a list object and would like to do sorting of those objects using jQuery or JavaScript. Below is the sample JSON.

[{
  "lvl1": "18 value",
  "db": "Corporate",
  "il": "Exe",
  "dt": "Instruction",
  "text": "Technical",
  "id": "1218122446"
},
{
  "lvl1": "50000 Vd",
  "db": "Americas Region",
  "il": "Supporting",
  "dt": "Startpage",
  "text": "Americastest",
  "id": "1014225610"
},
{
  "lvl1": "520000 A",
  "lvl2": "510300 b",
  "lvl3": "102000 c",
  "lvl4": "130300 d,
  "lvl5": "105330 e"
  "db": "Americas",
  "il": "Supporting",
  "dt": "Startpage",
  "text": "Americas",
  "id": "1014225610"
},
{
  "lvl1": "50000 Vas",
  "lvl2": "50300 EBEA",
  "lvl3": "10000 person1",    
  "db": "America",
  "il": "Support",
  "dt": "Startpage",
  "text": "test",
  "id": "1014225610"
},
{
  "lvl1": "210505 Executive",
  "db": "America",
  "il": "Support",
  "dt": "Startpage",
  "text": "1test",
  "id": "1014225610"      
}]

I would like to sort the objects using lvl1 and and proceed to next level sorting using DB and so on. How can we achieve this using Javascript/jQuery? We can use the array.sort() method for single value. How we can modify this for multiple key values. Please help me to achieve this.

0 Answers