---
title: last
framework: swift
role: symbol
role_heading: Instance Property
path: swift/string/last
---

# last

The last element of the collection.

## Declaration

```swift
var last: Self.Element? { get }
```

## Discussion

Discussion If the collection is empty, the value of this property is nil. let numbers = [10, 20, 30, 40, 50] if let lastNumber = numbers.last {     print(lastNumber) } // Prints "50" note: O(1)

## See Also

### Getting Characters and Bytes

- [subscript(_:)](swift/string/subscript(_:)-lc0v.md)
- [first](swift/string/first.md)
- [randomElement()](swift/string/randomelement().md)
- [randomElement(using:)](swift/string/randomelement(using:).md)
