You can also use zip from lodash. Since the function takes a sequence of arguments and you have an array, you'll need to spread the array with ...
const _ = require("lodash");
const arrData = [[1,2,4,6],[3,8,7],[12,13],[],[9,10]];
const z = _.zip(...arrData)
This will give you the following result:
[
[ 1, 3, 12, undefined, 9 ],
[ 2, 8, 13, undefined, 10 ],
[ 4, 7, undefined, undefined, undefined ],
[ 6, undefined, undefined, undefined, undefined ]
]
You can already see it's in the order that you want. Now to clean things up. You can use flatMap in its simplest form to flatten the array.
// lodash
const fm = _.flatMap(z)
// or with Array.prototype.flat()
const fm = z.flat()
This will give you a single array.
[
1, 3, 12,
undefined, 9, 2,
8, 13, undefined,
10, 4, 7,
undefined, undefined, undefined,
6, undefined, undefined,
undefined, undefined
]
Now you just need to remove all the undefined elements by filtering (keeping) all the elements that are not undefined.
// lodash
_.filter(fm, _.negate(_.isUndefined))
and you have your final result.
[1, 3, 12, 9, 2, 8, 13, 10, 4, 7, 6]
There are many ways to solve this issue so you'll need to decide based on your particular case and balance simplicity, code legibility, efficiency, etc.