【问题标题】:Javascript: How to merge the string values of two arrays?Javascript:如何合并两个数组的字符串值?
【发布时间】:2013-05-07 18:42:30
【问题描述】:

我想使用 _.zip function of Underscore.js 从两个数组创建对。

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

done with integers 时这似乎工作正常,但 using strings 时结果令人困惑:

对 = 3,3,3,3,3,3

相反,我希望得到以下结果:

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

更新:
感谢 cmets,我发现所描述的行为确实适用于在 Ubuntu 上运行的 Chromium。但是,当我在 Ubuntu 上的 Firefox 中运行相同的脚本时,会返回预期的结果。

【问题讨论】:

  • 这绝对令人困惑,因为this code does not produce that result.
  • 它对我有用。 (编辑上面使用字符串,仍然可以正常工作:jsfiddle.net/nmR7b/1
  • 在 XUbuntu 13.04、Chromium 版本 25.0.1364.160 Ubuntu 13.04 (25.0.1364.160-0ubuntu3) 下运行良好。 izuriel 使用 (alpha, one),(beta, two),(gamma, three) 发布警报的 jsFiddle。

标签: javascript arrays string underscore.js chromium


【解决方案1】:

filed a bug 解决问题。

【讨论】:

    猜你喜欢
    • 2011-03-25
    • 2018-02-14
    • 2017-04-01
    • 1970-01-01
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    • 2018-06-17
    • 1970-01-01
    相关资源
    最近更新 更多