Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I zip two arrays into one array of strings containing the values

For instance, if I have two arrays that look like this:

var array1 = ['a','b'];
var array2 = [1, 1];

The output array should be:

var newArray = ['a:1', 'b:1']
like image 916
Frantz Augustin Avatar asked Dec 19 '22 01:12

Frantz Augustin


1 Answers

You could use map like this:

var array1 = ['a','b'], array2 = [1, 1];
var newArray = array1.map((e, i) => `${e}:${array2[i]}`);

console.log(newArray);
like image 157
mdatsev Avatar answered Dec 28 '22 23:12

mdatsev