To join arrays in Swift, you can use the + operator or the append method.
In this example,
arr1
and arr2
.+
operator to concatenate elements of arr2
to arr1
.result
containing elements from both arr1
and arr2
.var arr1 = [1, 2, 3]
var arr2 = [4, 5, 6]
var result = arr1 + arr2
print("Joined Array:", result)
Joined Array: [1, 2, 3, 4, 5, 6]
In this example,
arr1
and arr2
.append
method to append elements of arr2
to arr1
.result
containing elements from both arr1
and arr2
.var arr1 = [1, 2, 3]
var arr2 = [4, 5, 6]
arr1.append(contentsOf: arr2)
print("Joined Array:", arr1)
Joined Array: [1, 2, 3, 4, 5, 6]
In this tutorial, we learned How to Join Arrays in Swift language with well detailed examples.