---
title: "indices(where:)"
framework: swift
role: symbol
role_heading: Instance Method
path: "swift/string/unicodescalarview/indices(where:)"
---

# indices(where:)

Returns the indices of all the elements that match the given predicate.

## Declaration

```swift
func indices(where predicate: (Self.Element) throws -> Bool) rethrows -> RangeSet<Self.Index>
```

## Parameters

- `predicate`: A closure that takes an element as its argument and returns a Boolean value that indicates whether the passed element represents a match.

## Return Value

Return Value A set of the indices of the elements for which predicate returns true.

## Discussion

Discussion For example, you can use this method to find all the places that a vowel occurs in a string. let str = "Fresh cheese in a breeze" let vowels: Set<Character> = ["a", "e", "i", "o", "u"] let allTheVowels = str.indices(where: { vowels.contains($0) }) // str[allTheVowels].count == 9 note: O(n), where n is the length of the collection.
