<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: 18.0.0 -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/AnyBidirectionalCollection/indices(of:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SlsSQ7ElementRpzrlE7indices2ofs8RangeSetVy5IndexQzGAB_tF::SYNTHESIZED::s:s26AnyBidirectionalCollectionV"
  },
  "title" : "indices(of:)"
}
-->

# indices(of:)

Returns the indices of all the elements that are equal to the given
element.

```
func indices(of element: Self.Element) -> RangeSet<Self.Index>
```

## Parameters

`element`

An element to look for in the collection.

## Return Value

A set of the indices of the elements that are equal to
`element`.

## Discussion

For example, you can use this method to find all the places that a
particular letter occurs in a string.

```
let str = "Fresh cheese in a breeze"
let allTheEs = str.indices(of: "e")
// str[allTheEs].count == 7
```

> Complexity: O(*n*), where *n* is the length of the collection.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)