array = [['10','8'],['11','4'],['18','7'],['7','6'],['8','7'],['9','5']] function sortNumber(a,b){return a[0]-b[0]} let newArray = array.sort(sortNumber)
var groupNum = 3;
var arr1 = [['10','8'],['11','4'],['18','7'],['7','6'],['8','7'],['9','5']];
var arr2 = [];
for (var i = arr1.length; i > 0 ; i -= groupNum) {
arr2.push(arr1.slice(i - groupNum, i));
}
console.log(arr2) // [['7','6'],['8','7'],['9','5'],['10','8'],['11','4'],['18','7']]
array = [['10','8'],['11','4'],['18','7'],['7','6'],['8','7'],['9','5']]
function sortNumber(a,b){return a[0]-b[0]}
let newArray = array.sort(sortNumber)
newArray 应该就是你要的结果了
你这个二维数组的排列的结果,好像是用的数组中的每个元素(数组)中的第一个下标的元素去比较的,那就转化成一个一维数组排序不就不好了吗?一维数组排好序,再将原二维数组利用index对应上一维数组排序。
逻辑实现思路:
var twoArray = [['10','8'],['11','4'],['18','7'],['7','6'],['8','7'],['9','5']];