Question: Here i my array of subarrays

```
const array = [
[0, 1, 2, 3],             // Loop from top to bottom?
[4, 5, 6, 7, 8, 9],       // |
[10, 11, 12, 13, 14],     // |
[15, 16, 17, 18, 19],     // |
]                         // V

```

And Im trying to get this output

```
newArray = [0, 4, 10, 15, 1, 5, 11, 16, 2, 6, 12 ...] 

```

This is what iv'e come up with so far

```
      let idx = 0;
      let newArray = []
      for (let i = 0; i < array.length; i++) {
        for (let j = 0; j < array[i].length; j++) {
          newArray.push(array[idx][j])
          idx++;
        }
        idx = 0;
      }

```

Answer: 
this is a possible solution:

```js
const array = [
  [0, 1, 2, 3],             // Loop from top to bottom?
  [4, 5, 6, 7, 8, 9],       // |
  [10, 11, 12, 13, 14],     // |
  [15, 16, 17, 18, 19],     // |
]
// if there is "more" to read
let hasMore = true;
// result
const res = [];
// "column" index
let el = 0;
while(hasMore){
  // let's assume there is nothing more to read
  hasMore = false;
  // go through all the elements in the input array
  for(let i = 0; i < array.length; i++){ 
    // if the el-th element exists
    if(array[i][el] != undefined){
      // there there might be something more to read
      // with "something more" I mean that exists the el+1 th column
      hasMore = true;
      // add the element
      res.push(array[i][el])
    }
  }
  // move to the next column
  el++;
}
console.log(res);
```

a functional style possible solution instead could be:

```js
const array = [
  [0, 1, 2, 3],             // Loop from top to bottom?
  [4, 5, 6, 7, 8, 9],       // |
  [10, 11, 12, 13, 14],     // |
  [15, 16, 17, 18, 19],     // |
]
const res = array.flatMap(
  el => el.map(
    (o, i) => ({
      index: i,
      el: o
    })
  ))
  .sort((a, b) => a.index - b.index)
  .map(({el}) => el)

console.log(res)
```
Not sure if this is a solution as this will create a new array, but might help.
`var newArray = Array.prototype.concat.apply([], array);`