按第5个字段对多维数组进行排序

时间:2011-08-26 13:29:02

标签: javascript arrays sorting multidimensional-array

我有一个数组数组(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]
];

我想对这个数组进行排序,按升序排序,按第5个字段(浮点数)。

有可能吗?

1 个答案:

答案 0 :(得分:8)

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