按屬性值對對象數組進行排序 - Sorting an array of objects by property values

問題:

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
相關文章
相關標籤/搜索