Swift .remove()
Published Oct 11, 2022
Contribute to Docs
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"]
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
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