Created
August 7, 2019 18:14
-
-
Save greathmaster/4560a213a59f8b5ca457832d6f619f4a to your computer and use it in GitHub Desktop.
Get the column of a 2D array/matrix in JS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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