Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How To Update Last Element Of an Array?

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)")
}
 
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading