Skip to content

Instantly share code, notes, and snippets.

@greathmaster
Created August 7, 2019 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greathmaster/4560a213a59f8b5ca457832d6f619f4a to your computer and use it in GitHub Desktop.
Save greathmaster/4560a213a59f8b5ca457832d6f619f4a to your computer and use it in GitHub Desktop.
Get the column of a 2D array/matrix in JS
//Get the column of a 2D array in JS
//Taken from https://stackoverflow.com/questions/7848004/get-column-from-a-two-dimensional-array
const arrayColumn = (arr, n) => arr.map(x => x[n]);
const twoDimensionalArray = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
console.log(arrayColumn(twoDimensionalArray, 0));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment