Merge two arrays with alternating Values

前端 未结 9 2147
南笙
南笙 2020-12-03 14:19

i would like to merge 2 arrays with a different length:

let array2 = [\"a\", \"b\", \"c\", \"d\"];
let array2 = [1, 2];

let outcome = [\"a\",1 ,\"b\", 2, \"         


        
9条回答
  •  渐次进展
    2020-12-03 15:11

    ONELINER: I assume that x=array1, y=array2, x and y can be arbitrary arr

    [...x,...y].reduce((l,c,i)=>(i

    working example (for 3 cases)

提交回复
热议问题