Swift .removeLast()

Christine_Yang's avatar
Published Oct 11, 2022

The .removeLast() method removes the last element in an array.

  • 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

Syntax

arrayName.removeLast()

Example

var topBabyNames = ["Sophia", "Liam", "Riley", "Jackson", "Olivia", "Noah"]
topBabyNames.removeLast()
print(topBabyNames)

This will output:

["Sophia", "Liam", "Riley", "Jackson", "Olivia"]

All contributors

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