问题:
I've got the following objects using AJAX and stored them in an array: 我使用AJAX获得了以下对象并将它们存储在数组中:
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 do I create a function to sort the objects by the price
property in ascending or descending order using JavaScript only? 如何创建仅使用JavaScript 按 price
属性按升序 或 降序对对象进行排序的函数?
解决方案:
参考一: https://stackoom.com/question/46kS/按属性值对对象数组进行排序参考二: https://oldbug.net/q/46kS/Sorting-an-array-of-objects-by-property-values
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4308214