<!--
{
  "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/MutableCollection/removeSubranges(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SMsSmRzrlE15removeSubrangesyys8RangeSetVy5IndexSlQzGF"
  },
  "title" : "removeSubranges(_:)"
}
-->

# removeSubranges(_:)

Removes the elements at the given indices.

```
mutating func removeSubranges(_ subranges: RangeSet<Self.Index>)
```

## Parameters

`subranges`

The indices of the elements to remove.

## Discussion

For example, this code sample finds the indices of all the negative
numbers in the array, and then removes those values.

```
var numbers = [5, 7, -3, -8, 11, 2, -1, 6]
let negativeIndices = numbers.indices(where: { $0 < 0 })

numbers.removeSubranges(negativeIndices)
// numbers == [5, 7, 11, 2, 6]
```

> 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)