---
title: "firstIndex(of:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/string/firstindex(of:)"
---

# firstIndex(of:)

Returns the first index where the specified value appears in the collection.

## Declaration

```swift
func firstIndex(of element: Self.Element) -> Self.Index?
```

## Parameters

- `element`: An element to search for in the collection.

## Return Value

Return Value The first index where element is found. If element is not found in the collection, returns nil.

## Discussion

Discussion After using firstIndex(of:) to find the position of a particular element in a collection, you can use it to access the element by subscripting. This example shows how you can modify one of the names in an array of students. var students = ["Ben", "Ivy", "Jordell", "Maxime"] if let i = students.firstIndex(of: "Maxime") {     students[i] = "Max" } print(students) // Prints "["Ben", "Ivy", "Jordell", "Max"]" note: O(n), where n is the length of the collection.

## See Also

### Finding Characters

- [contains(_:)](swift/string/contains(_:).md)
- [allSatisfy(_:)](swift/string/allsatisfy(_:).md)
- [contains(where:)](swift/string/contains(where:).md)
- [first(where:)](swift/string/first(where:).md)
- [firstIndex(where:)](swift/string/firstindex(where:).md)
- [last(where:)](swift/string/last(where:).md)
- [lastIndex(of:)](swift/string/lastindex(of:).md)
- [lastIndex(where:)](swift/string/lastindex(where:).md)
- [max()](swift/string/max().md)
- [max(_:_:)](swift/string/max(_:_:).md)
- [max(by:)](swift/string/max(by:).md)
- [min()](swift/string/min().md)
- [min(_:_:)](swift/string/min(_:_:).md)
- [min(by:)](swift/string/min(by:).md)
