Skip to content
Advertisement

Transpose 2d array, join second level with commas, and join first level with pipes

I have the following two-dimensional array:

JavaScript

I want to convert columns to rows then reduce the matrix to a string like the following:

JavaScript

Advertisement

Answer

I’m assuming that you have this array:

JavaScript

In which case, you can do this:

JavaScript

See it working

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement