Get column in array of arrays
Below is a quick example i think:
var column_number = 2;
var column = [];
for(var i=0; i<9; i++) {
var value = matrix[i][column_number];
column.push(value);
}
The “fastest” in terms of “least code” would probably be Array.prototype.map
:
const getColumn = (anArray, columnNumber) =>
anArray.map(row => row[columnNumber]);
const getColumn = (anArray, columnNumber) =>
anArray.map(row => row[columnNumber]);
const arr = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
];
console.log(getColumn(arr, 0));