To zip two arrays in JavaScript, we use the map
method.
For instance, we write
const a = [1, 2, 3];
const b = ["a", "b", "c"];
const c = a.map((e, i) => {
return [e, b[i]];
});
console.log(c);
to call a.map
with a callback that returns an array with arrays of items in a
and the items in b
at the same position as the item in a
.