本文介绍了如何在javascript中对多维数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数组如下
var arry = [ [1, "Convention Hall", "Mumbai", 10, "XYZ Company"],
[2, "Auditorium", "Delhi", 10, "ABC Company"],
[3, "CenterHall", "Bangalore", 10, "ZZZ Company"],
....
]
我想根据数组的第三项按字母顺序对数组进行排序,即 arry[n][2]
I want to sort the array alphabetically based on the third item of array i.e arry[n][2]
如何做到这一点.
推荐答案
您可以使用 arry.sort()
.默认为字母数字和升序.
You can use the arry.sort()
. The default is alphanumeric and ascending.
那就是:
var arry = [ [1, "Convention Hall", "Dangalore", 10, "XYZ Company"],
[2, "Auditorium", "Belhi", 10, "ABC Company"],
[3, "CenterHall", "Aumbai", 10, "ZZZ Company"],
];
var x =arry.sort(function(a,b){ return a[2] > b[2] ? 1 : -1; });
alert(x);
这篇关于如何在javascript中对多维数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!