i am trying to get sequence index of each array of array like I have an element of the array and that 5 arrays have multiple elements and I want to get the first index of each array then the second and so.
below is my array data
const arrData = [[1,2,4,6],[3,8,7],[12,13],[],[9,10]];
and my expected outout [1,3,12,9,2,8,13,10,4,7,6]
give me some sort of solution to fix my issue
Following might work:
const src = [[1,2,4,6],[3,8,7],[12,13],[],[9,10]],
pickByOne = arr => {
const result = [],
{length} = arr.flat()
while(result.length < length){
for(a of arr){
a.length && result.push(a.shift())
}
}
return result
}
console.log(pickByOne(src))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With