I suggest to use a built in comparer and chain the wanted sort order with logical or ||
.
function customSort(a, b) {
return a[3].localeCompare(b[3]) || a[1].localeCompare(b[1]);
}
Working example:
var array = [_x000D_
[0, 'Aluminium', 0, 'Francis'],_x000D_
[1, 'Argon', 1, 'Ada'],_x000D_
[2, 'Brom', 2, 'John'],_x000D_
[3, 'Cadmium', 3, 'Marie'],_x000D_
[4, 'Fluor', 3, 'Marie'],_x000D_
[5, 'Gold', 1, 'Ada'],_x000D_
[6, 'Kupfer', 4, 'Ines'],_x000D_
[7, 'Krypton', 4, 'Joe'],_x000D_
[8, 'Sauerstoff', 3, 'Marie'],_x000D_
[9, 'Zink', 5, 'Max']_x000D_
];_x000D_
_x000D_
array.sort(function (a, b) {_x000D_
return a[3].localeCompare(b[3]) || a[1].localeCompare(b[1]);_x000D_
});_x000D_
_x000D_
document.write('<pre>');_x000D_
array.forEach(function (a) {_x000D_
document.write(JSON.stringify(a) + '<br>');_x000D_
});
_x000D_