let array1 = ["Albert","Bobby"]
let array2 = ["Charles", "David"]
How do merge two array so that the out put would be ["Albert", "Charles", "Bobby", "David"]
You can use zip
to combine your two arrays, and thereafter apply a .flatMap
to the tuple elements of the zip sequence:
let array1 = ["Albert","Bobby"]
let array2 = ["Charles", "David"]
let arrayMerged = zip(array1,array2).flatMap{ [$0.0, $0.1] }
print(arrayMerged) // ["Albert", "Charles", "Bobby", "David"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With