How to Sort Nested Javascript Array -


i have array

var a=[['test':'1','test1':'2','test2':{'test3':'3','test4':'4'}],['test':'2','test1':'2','test2':{'test3':'1','test4':'2'}]]; 

i can sort array using test , test 1 fields. have no idea sort using test3 or test4. how can array sorted.

code

[{"hotelid":18,"hotelname":"trader","hotelalias":"trader-hotel","hotelstreet":null,"address":"no.18","hoteldescription":"near shwedagone pagoda","hotellat":16.819910049438,"hotellng":96.130912780762,"cityid":33,"regionid":1,"breakfast":1,"lunch":0,"dinner":0,"snack":0,"wifi":1,"createdon":"2016-08-24 14:09:57","city":{"cityid":33,"cityname":"bahan","regionid":1,"citypostcode":"11210","citydescription":null,"region":{"regionid":1,"regionname":"yangon","iso":"mm-06","regiondescription":"old capital of myanmar"}},"room_count":null,"room_lock_count":null},{"hotelid":17,"hotelname":"yuzana","hotelalias":"yuzana-hotel","hotelstreet":null,"address":"no.18","hoteldescription":"near shwedagone pagoda","hotellat":16.819910049438,"hotellng":96.130912780762,"cityid":33,"regionid":1,"breakfast":1,"lunch":0,"dinner":0,"snack":0,"wifi":1,"createdon":"2016-08-22 17:47:42","city":{"cityid":33,"cityname":"bahan","regionid":1,"citypostcode":"11210","citydescription":null,"region":{"regionid":1,"regionname":"yangon","iso":"mm-06","regiondescription":"old capital of myanmar"}},"room_count":null,"room_lock_count":null},{"hotelid":16,"hotelname":"strand","hotelalias":"strand-hotel","hotelstreet":null,"address":"no.18","hoteldescription":"the river view","hotellat":16.819910049438,"hotellng":96.130912780762,"cityid":12,"regionid":1,"breakfast":1,"lunch":0,"dinner":0,"snack":1,"wifi":1,"createdon":"2016-08-22 13:57:27","city":{"cityid":12,"cityname":"kyauktada","regionid":1,"citypostcode":null,"citydescription":null,"region":{"regionid":1,"regionname":"yangon","iso":"mm-06","regiondescription":"old capital of myanmar"}},"room_count":null,"room_lock_count":null},{"hotelid":14,"hotelname":"novotal","hotelalias":"novotal-hotel","hotelstreet":null,"address":"kamayut","hoteldescription":"the best hotel","hotellat":16.819910049438,"hotellng":96.130912780762,"cityid":11,"regionid":1,"breakfast":1,"lunch":0,"dinner":0,"snack":1,"wifi":1,"createdon":"2016-08-22 11:48:35","city":{"cityid":11,"cityname":"kamayut","regionid":1,"citypostcode":null,"citydescription":null,"region":{"regionid":1,"regionname":"yangon","iso":"mm-06","regiondescription":"old capital of myanmar"}},"room_count":{"hotelid":14,"qty":7},"room_lock_count":{"hotelid":14,"qty":7}}] 

this should sort on test3.

a.sort(function (item1, item2) {   if (item1.test2.test3 < item2.test2.test3) return -1;   if (item1.test2.test3 > item2.test2.test3) return 1;   return 0; }); 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -