Hello friend,
I have a javascipt array object. Now i will try to sort price in this array.
For Example:
var data = [
{
"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"
}
];
Javascript sort function sorts the value of array by passing index key. It will sort price as ascending order by using below code.
data.sort(function(a, b) {
return parseFloat(a.price) - parseFloat(b.price);
});
0 Comment(s)