var arr = [[1, 2, 3], [7, 2, 3], [3, 2, 3]]for(var i in arr) console.log(arr[i])arr.sort(function(){return x[0]-y[0]})//按每个数组的第一个元素的大小来排序;x,y分别是相邻的两个数组元素如[1,2,3],[7,2,3];函数是自定义的,所以还是很灵活的for(var i in arr) console.log(arr[i])//可以看到变化
<!DOCTYPE HTML><html>
<meta charset="UTF-8" />
<head>
<title>YuGiOh Power Of Chaos</title>
<style type="text/css">
</style>
<script type="text/javascript">
var array = [
[
1, 2, 3
], [
4, 5, 6
], [
3, 5, 6
]
]
array.sort (function (a, b)
{
var x = a[0], y = b[0]
if (x > y)
{
return 1
}
else if (x < y)
{
return -1
}
else
{
return 0
}
})
console.log (array)
</script>
</head>
<body>
</body>
</html>