let array1 = ["Albert","Bobby"]
let array2 = ["Charles", "David"]
如何合并两个数组,以便输出为["Albert", "Charles", "Bobby", "David"]
答案 0 :(得分:15)
您可以使用zip
组合两个数组,然后将.flatMap
应用于zip序列的元组元素:
let array1 = ["Albert","Bobby"]
let array2 = ["Charles", "David"]
let arrayMerged = zip(array1,array2).flatMap{ [$0.0, $0.1] }
print(arrayMerged) // ["Albert", "Charles", "Bobby", "David"]
答案 1 :(得分:-3)
试一试
var a = ["one", "two"]
var b = ["three", "four"]
var c = a + b
print(c)