Sorting an array of JavaScript objects -
Sorting an array of JavaScript objects -
i read next 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 , descending order using javascript?
sort homes cost in ascending order:
class="lang-js prettyprint-override">homes.sort(function(a, b) { homecoming parsefloat(a.price) - parsefloat(b.price); });
javascript arrays sorting
Comments
Post a Comment