With this array:
var arr = [];
arr[0] = [1, 'Peter', 3];
arr[1] = [1, 'Mary', 2];
arr[2] = [0, 'David', 5];
arr[3] = [0, 'John', 4];
arr[4] = [0, 'Billy', 1];
This works fine:
arr.sort(function (a,b) {
console.log(a[2]);
if (a[2] > b[2]) return 1;
if (a[2] < b[2]) return -1;
return 0;
});
But with an array like this:
var arr = [];
arr[0] = [1, 1, 0, 0, 0];
arr[1] = ['Peter', 'Mary', 'David', 'John', 'Billy'];
arr[2] = [3, 2, 5, 4, 1];
A[2] gets 0-David.
I returned everything, I really cannot figure it out. Please, do you know how I could sort the second array according to arr[2] list?
arrand in the second you are sorting a mash of the subarrays, soarr.sortwill never do the trick because you are not trying to sortarr. As @epascarello said, you will be better mapping one to the other.