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

# setObject(_:forKeyedSubscript:)

Sets the value’s JavaScript property named with the specified key, allowing subscript syntax.

```
func setObject(_ object: Any!, forKeyedSubscript key: Any!)
```

## Parameters

`object`

The value to set for the named JavaScript property.

`key`

The name of a property in the JavaScript object.

## Discussion

This method is equivalent to the [`setValue(_:forProperty:)`](/documentation/JavaScriptCore/JSValue/setValue(_:forProperty:)) method, but provides Objective-C subscripting support.

---

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)