How to get the third column from a matrix (2D array) in JavaScript

1 Answer

0 votes
const arr = [
  [1, 2, 3, 5, 6],
  [4, 5, 6, 5, 6],
  [7, 8, 9, 5, 6]
];

const col3 = arr.map(function(value,index) { return value[2]; });

console.log(col3); 


  
    
    
/*
run:
    
[3, 6, 9]
    
*/

 



answered Feb 21, 2021 by avibootz

Related questions

...