<!--
{
  "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/JSContext/objectForKeyedSubscript(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:objc(cs)JSContext(im)objectForKeyedSubscript:"
  },
  "title" : "objectForKeyedSubscript(_:)"
}
-->

# objectForKeyedSubscript(_:)

Returns the value of the specified JavaScript property in the context’s global object, allowing subscript getter syntax.

```
func objectForKeyedSubscript(_ key: Any!) -> JSValue!
```

## Parameters

`key`

The name of a JavaScript property in the context’s global JavaScript object.

## Return Value

The JavaScript property named by `key`, or `nil` if no such field or function exists.

## Discussion

This method first constructs a [`JSValue`](/documentation/JavaScriptCore/JSValue) object from the `key` parameter, then uses that value in JavaScript to look up the name of a property in the context’s global object.

---

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)