milesma milesma - 1 year ago 47
Javascript Question

How to combine two same lengths array into one same length array with element joined by a separator


a=["a", "b", "c"];
x=["x", "y", "z"];

combine/join the two list: the expected result:

ax=["a:x", "b:y", "c:z"];

How? One liner is better.

Something like python's zip function.


Answer Source

In ES6:

let a = ["a", "b", "c"], 
    x = ["x", "y", "z"]; 
let ax = (value,index) => value + ':' + x[index] );