zip javascript code example
Example 1: how to zip two arrays in javascript
let ladies = ["Elise", "Mary"]
let gentlemen = ["John", "Rick"]
var doubleDate = ladies.map(function(lady, i) {
return [lady, gentlemen[i]];
});
console.log(doubleDate)
Example 2: java script zip function
// Zipping two arrays into an object, better performance than map
let labels = ['a', 'b', 'c']
let values = [1, 2, 3]
let out = {}
for (var i = 0; i < labels.length; i++) {
out = { ...out, [labels[i]]: values[i] }
}
console.debug(out);
// { a: 1, b: 2, c: 3 }