.remove()

The .remove() method removes an element from an array at a specified index.

Syntax

arrayName.remove(at: index)

Example

var topBabyNames = ["Sophia", "Liam", "Riley", "Jackson", "Olivia", "Noah"]
topBabyNames.remove(at: 2)
print(topBabyNames)

In the example above, the element at index 2 is removed. This will output:

["Sophia", "Liam", "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