---
title: "objectForKeyedSubscript(_:)"
framework: javascriptcore
role: symbol
role_heading: Instance Method
path: "javascriptcore/jscontext/objectforkeyedsubscript(_:)"
---

# objectForKeyedSubscript(_:)

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

## Declaration

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

## Parameters

- `key`: The name of a JavaScript property in the context’s global JavaScript object.

## Return Value

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

## Discussion

Discussion This method first constructs a 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.

## See Also

### Accessing JavaScript global state with subscripts

- [setObject(_:forKeyedSubscript:)](javascriptcore/jscontext/setobject(_:forkeyedsubscript:).md)
