Swift Array – Delete First Element
To delete first element of an Array in Swift, call dropFirst()
method on the array. dropFirst()
method without any value for argument, returns a new array with first element dropped from the trailing end of given array.
The syntax to call dropFirst()
method on the array is
var result = arr.dropFirst()
Example
In the following program, we will initialize an array with some values, and delete the first element using dropFirst()
method.
main.swift
var arr = [1, 99, 6, 74, 5] let result = arr.dropFirst() print("Original Array: \(arr)") print("Resulting Array: \(result)")
Output
Conclusion
In this Swift Tutorial, we learned how to get the subsequence which contains the elements of given array, with the first element dropped.