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

django - How can I change user group without delete record -

java - EclipseLink JPA Object is not a known entity type -

java - Need to add SOAP security token -