![](/img/trans.png)
[英]How to merge two almost identical arrays/objects (with underscorejs or similiar libary)?
[英]How to join values of two arrays using underscoreJS
假設我們有兩個數組:
var a = ['Tomo', 'Joseph','Alan'];
var b = ['Brzica', 'Smith', 'Adams'];
如何使用undersoreJS(或純JavaScript,如果沒有underscore的話)合並這些數組以獲取:
c=['Tomo Brzica','Joseph Smith', 'Alan Adams']
提前致謝!
你可以試試這個
c = _.map(_.zip(a, b), function (elem) {
return elem.join(" ");
});
嘗試這個:
c = _.map(a, function (item, index) {
return item + " " + b[index];
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.