Scenario:
I have a 2 Dimensional array consisting of values, for example:
const arr = [ [ 1, 2, 3, 4, 5, 6 ],
[ 7, 8, 9, 0, 1, 2 ],
[ 3, 4, 5, 6, 7, 8 ],
[ 9, 0, 1, 2, 3, 4 ] ];
The number of rows can vary, though will always be a multiple of two.
Question:
How can I extract columns out of this array using .map() so that I can get sub-arrays each containing two columns?
Example:
// columns 1 and 2:
ext1 = [ [ 1, 2 ],
[ 7, 8 ],
[ 3, 4 ],
[ 9, 0 ] ];
// columns 3 and 4:
ext2 = [ [ 3, 4 ],
[ 9, 0 ],
[ 5, 6 ],
[ 1, 2 ] ];
// columns 5 and 6:
ext3 = [ [ 5, 6 ],
[ 1, 2 ],
[ 7, 8 ],
[ 3, 4 ] ];