s-yadav / jsonQ

A JavaScript library to make manipulation and extraction of data from a JSON very easy and fast.
MIT License
202 stars 69 forks source link

How to do sorting for json array #6

Open roshan-ship-it opened 8 years ago

roshan-ship-it commented 8 years ago

hi, I have one small example: var jsonObj = [{ "age": 30, "name": "James Martin"
}, { "age": 44, "name": "ABC", } ]

var family = jsonQ(JSON.stringify(jsonObj)), pnames = family.find('name');

result ==> i am getting same result asc or desc sorting..this is happening only if i have Json array...Could you please suggest how to approach this kind of problem..Basically i have requirement where i need to do sorting based on column in json array.. pnames.sort("name",{order:'ASC'}).value() ["James Martin", "ABC"] pnames.sort("name",{order:'DESC'}).value() ["James Martin", "ABC"]