Instance Method

dropFirst()

Returns a subsequence containing all but the first element of the sequence.

Declaration

func dropFirst() -> Self.SubSequence

Return Value

A subsequence starting after the first element of the sequence.

Discussion

The following example drops the first element from an array of integers.

let numbers = [1, 2, 3, 4, 5]
print(numbers.dropFirst())
// Prints "[2, 3, 4, 5]"

If the sequence has no elements, the result is an empty subsequence.

let empty: [Int] = []
print(empty.dropFirst())
// Prints "[]"

Complexity: O(1)

See Also

Excluding Elements

func dropLast() -> Self.SubSequence

Returns a subsequence containing all but the last element of the sequence.