Javascript: How to merge the string values of two arrays?

a 夏天 提交于 2020-01-26 04:54:22

问题


I want to use the _.zip function of Underscore.js to create pairs from two arrays.

var a = ["alpha", "beta", "gamma"];
var b = ["one", "two", "three"];
var pairs = _.zip(a, b);
alert("pairs = " + pairs);

This seems to work fine when done with integers however when using strings the result is confusing:

pairs = 3,3,3,3,3,3

Instead I expect the following result:

pairs = [["alpha", "one"], ["beta", "two"], ["gamma","three"]]

Update:
Thanks to the comments I discovered that the described behavior does apply to Chromium running on Ubuntu. However the expected result is return when I run the same script in Firefox on Ubuntu.


回答1:


I filed a bug for the problem.



来源:https://stackoverflow.com/questions/16426293/javascript-how-to-merge-the-string-values-of-two-arrays

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!