Javascript Lo-Dash 如何将 3 个 1D 组合成单个 1x3 数组

Javascript Lo-Dash how to combine 3 1D into as single 1x3 arrary

如何将 3 - 1D 数组合并为单个 2 D 数组

a1=   ["1a","2a","3a"]
a2=   ["1b","2b","3b"]
a3=  ["1c","2c","3c"]


result = 1a, 1b, 1c,
          2a, 2b, 2c,
          3a, 3b, 3c

你会使用 flatten():

var a1 = [ '1a', '2a', '3a' ],
    a2 = [ '1b', '2b', '3b' ],
    a3 = [ '1c', '2c', '3c' ];

_.flatten([ a1, a2, a3 ]);
// → [ "1a", "2a", "3a", "1b", "2b", "3b", "1c", "2c", "3c" ]

如果你想对输出进行排序,你可以使用 sortBy():

_([ a1, a2, a3 ]).flatten().sortBy().value()
// → [ "1a", "1b", "1c", "2a", "2b", "2c", "3a", "3b", "3c" ]