.removeFirst()

The .removeFirst() method removes the first element in an array.

Syntax

arrayName.removeFirst()

Example

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

This will output:

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

Contributors

Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Swift on Codecademy