2011-08-26 49 views
3

排序多維數組我有陣列的陣列(2名維):由第五字段

var myArray = [ 
    ["DVD Title 1","label1","releasedate2","details1", 5241.2541], 
    ["DVD Title 1","label3","releasedate1","details1", 8452.654], 
    ["DVD Title 1","label3","releasedate2","details1", 45465.5465], 
    ["DVD Title 1","label2","releasedate1","details1", 451.545], 
    ["DVD Title 1","label1","releasedate1","details1", 7458.6545], 
    ["DVD Title 2","label2","releasedaten","detailsn", 4545.545], 
    ["DVD Title 2","label1","releasedaten","detailsn", 545.545] 
]; 

我要排序該陣列中,爲了通過上升,由所述第五字段(浮點數)。

可能嗎?

+0

你是否甚至搜索過,它已經在這裏回答過。 – b01

+0

[Javascript:sort multidimensional array]可能重複(http://stackoverflow.com/questions/3886165/javascript-sort-multidimensional-array) – Shef

回答

8
myArray.sort(function(a,b){ 
    return a[4] - b[4]; 
}); 
+0

廢話,應該在我發佈前刷新。 – b01