Swift .removeLast()
Published Oct 11, 2022
The .removeLast() method removes the last element in an array.
Syntax
arrayName.removeLast()
Example
var topBabyNames = ["Sophia", "Liam", "Riley", "Jackson", "Olivia", "Noah"]topBabyNames.removeLast()print(topBabyNames)
This will output:
["Sophia", "Liam", "Riley", "Jackson", "Olivia"]
Learn Swift on Codecademy
- Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
- Includes 7 Courses
- With Certificate
- Beginner Friendly.13 hours
- A powerful programming language developed by Apple for iOS, macOS, and more.
- Beginner Friendly.12 hours