<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSValue/toRange()",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:objc(cs)JSValue(im)toRange"
  },
  "title" : "toRange()"
}
-->

# toRange()

Converts the value to a range.

```
func toRange() -> NSRange
```

## Return Value

A range representation of the value.

## Discussion

This method treats the value as a JavaScript object, reading the values of its `location` and `length` properties using the [`toDouble()`](/documentation/JavaScriptCore/JSValue/toDouble()) method and creating a <doc://com.apple.documentation/documentation/Foundation/NSRange-c.struct> structure from the result. If the value is not a JavaScript object or does not have the appropriate properties, the resulting range is invalid.

---

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)