[英]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: 如何使用undersoreJS(或纯JavaScript,如果没有underscore的话)合并这些数组以获取:
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];
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.