O'Reilly logo

Mastering Swift 4 - Fourth Edition by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Merging two arrays

To create a new array by adding two arrays together, we use the addition (+) operator. The following example shows how to use the addition (+) operator to create a new array that contains all the elements of two other arrays:

let arrayOne = [1,2]  
let arrayTwo = [3,4] 
var combined = arrayOne + arrayTwo //combine contains 1, 2, 3 and 4 

In the preceding code, arrayOne and arrayTwo are left unchanged, while the combined array contains the elements from arrayOne, followed by the elements from arrayTwo.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required