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

Sort Entire Array rather than just the found parameter #12

Open Cleanshooter opened 7 years ago

Cleanshooter commented 7 years ago

Rather than having the sort method return only the value of the provided key it would be more useful if there were an option to return the entire JSON object with all data still intact sorted based on the key/parameter identified. Returning an array of sorted values isn't that helpful when it comes to a sort command for most query languages.

s-yadav commented 7 years ago

Actually, sortMethod do inplace sorting so you can do just

var family = jsonQ(jsonObj);
family.sort('name');

So here now family jsonQ is a sorted object.

Right now .sort method returns a jsonQ object which is simialiar to (family.find('name')), but sorted. So if you do

var family = jsonQ(jsonObj);
var names = family.sort('name');

you will get the names

But yes, I agree it should return the family jsonQ object instead of names. Will check for the impact and will make this change.

jomy-joseph commented 6 years ago

Is this available now?