How To fetch Last element of an array and Update it . I have an array of string elements as well as Int, But I don’t know how to fetch last Element of an array.
mY array
var nums = [ 2, 4, 6, 8, 10 ]
>Solution :
There are multiple ways you can achieve the last element of an array such as following :
var nums = [ 2, 4, 6, 8, 10 ]
if let lastElement = nums.last {
print("Last Element : \(lastElement)")
}