How to get column from a two-dimensional array with JavaScript?

To get column from a two-dimensional array with JavaScript, we use the map method.

For instance, we write

const twoD = [
  [1, 2, 3],
  [4, 5, 6],
  [7, 8, 9],
];
const col3 = twoD.map((value, index) => {
  return value[2];
});

to call twoD.map with a callback that gets the 3rd item from each nested array with value[2].

An array with the vales returned by the callback is returned.