Start learning free

LESSON 99 OF 349 · ARRAYS I

Remove Items From Array in Swift in Swift

Lesson

Another way to change the data in an array is with the .remove(at:) method.

.remove(at:) takes one parameter which represents an index and removes the element placed at that index:

var threeArr = [1, 4, 6]

// Remove second element:
threeArr.remove(at: 1)

// threeArr has now the value [1, 6]

// Remove first element:
threeArr.remove(at: 0)

// threeArr has now the value [6]

Assignment
Follow the Coding Tutorial and let's play with some arrays.


Hint
Look at the examples above if you get stuck.


STEP 1 OF 2
    Ctrl + Enter to check

    Array Pop in Swift

    Keep going with SwiftAbout 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free