Sorting an array of JavaScript objects -


i read following objects using ajax , stored them in array:

var homes = [     {         "h_id": "3",         "city": "dallas",         "state": "tx",         "zip": "75201",         "price": "162500"     }, {         "h_id": "4",         "city": "bevery hills",         "state": "ca",         "zip": "90210",         "price": "319250"     }, {         "h_id": "5",         "city": "new york",         "state": "ny",         "zip": "00010",         "price": "962500"     } ]; 

how create function sort objects price property in ascending or descending order using javascript?

sort homes price in ascending order:

homes.sort(function(a, b) {     return parsefloat(a.price) - parsefloat(b.price); }); 

some documentation can found here.


Comments

Popular posts from this blog

How do you change vbulletin's home page to the forums instead of the default (CMS or Activity Stream)? -

c++ - Troubles when compiling phash program -