Remove Element From an Array at Specified Index

In this short Swift code example we will learn how:

  • Initialize an Array with 5 elements in Swift
  • Remove an element from an array at specified index
// Initialize Array with 5 elements
var myArray = [1,2,3,4,5]

// Print Array contents to preview
print(myArray)

// Remove element at index: 1
myArray.removeAtIndex(1)

// Print Array contents to preview
print(myArray)
		

Have a look at this code example on How to delete all items from an array in Swift

[raw_html_snippet id=”cookbookpagecoursesheader”]

Unit Testing Swift Mobile App

Apply Test-Driven Development(TDD) process to iOS mobile app development in Swift Preview this video course.