Такой еще вариант предложу...
var matrix4D = [
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1],
[1, 1, 1, 1]
];
var matrix4_D = [
[1, 1, 1, 3],
[1, 1, 6, 1],
[1, 2, 1, 10],
[9, 1, 1, 1],
[1, 1, 11, 1]
];
var matrix5D = [
[1, 2, 3, 4, 5],
[1, 1, 1, 3, 4],
[1, 1, 1, 1, 1]
];
alert(function_matrix(matrix4D));
alert(function_matrix(matrix4_D));
alert(function_matrix(matrix5D));
function function_matrix(arr){
var col = arr[0].length;
var row = 0;
var res = [];
while ((col > -1) && (row < arr.length)) {
res.push(arr[row++][--col]);
}
return res
};