简体   繁体   中英

How to join values of two arrays using underscoreJS

let's say that we have two arrays:

var a = ['Tomo', 'Joseph','Alan'];
var b = ['Brzica', 'Smith', 'Adams'];

How to merge these arrays using undersoreJS (or plain javascript if underscore is not the way to do it) to get:

c=['Tomo Brzica','Joseph Smith', 'Alan Adams']

Thanks in advance!

You can try this

c = _.map(_.zip(a, b), function (elem) {
    return elem.join(" ");
});

try this:

c = _.map(a, function (item, index) {
   return item + " " + b[index];
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM