There are quite a few libraries that implement a transpose function for arrays, but sometimes you don't want the hassle of installing them or the added dependencies. I'm sure I'm not the first to use this approach but most snippets found by a quick search are too verbose to comfortably drop in for a single use.
The most magical bit here is to use
Object.keys() on the
first row of the array which yields an array of column indexes, which
we can then use
map() on to extract each column in turn.
Love to see a terser implementation if you've found one.