這是我的數據。如何按高度對JavaScript數組進行排序並在控制檯中僅獲取打印高度
var data = [
{"firstName":"John", "lastName":"Doe", "age":"24", "height":"5.2"},
{"firstName":"Sam", "lastName":"Sam", "age":"28", "height":"6.0"},
{"firstName":"Anna", "lastName":"Smith", "age":"25", "height":"5.8"},
{"firstName":"Willam", "lastName":"Will", "age":"22", "height":"5.2"},
{"firstName":"Peter", "lastName":"Jones", "age":"23", "height":"6.2"}
];
這就是我所嘗試過的。
var sorted = data.sort(function(a, b){
return a.height - b.height;
});
console.log(data.sort(sorted));
請,你需要閱讀此之前問:http://stackoverflow.com/help/how-to-ask這是一個貧窮的創作的問題 –
你'重新排序你的數據一次,然後再次排序它通過排序的結果作爲比較函數? –