.removeLast()

Published Oct 11, 2022
Contribute to Docs

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"]

All contributors

Looking to contribute?

Learn Swift on Codecademy