how to get last element of an array in swifg code example
Example 1: how to get the last element of an array in swift
if let last = a.last {
print(last)
}
Example 2: how to get last element of an array in swifg
let myArray = ["Hello!", "World!"]
let capacity = myArray.count
let lastElement = myArray[capacity-1]
print(lastElement)
Example 3: get last element of array swift
let array = ["A", "B", "C", 1, 2, 3]
let size = array.count
last_element = array[size-1]
print(last_element)