<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSObjectSetPropertyForKey(_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:@F@JSObjectSetPropertyForKey"
  },
  "title" : "JSObjectSetPropertyForKey(_:_:_:_:_:_:)"
}
-->

# JSObjectSetPropertyForKey(_:_:_:_:_:_:)

Sets a property on an object using a JavaScript value as the property key.

```
func JSObjectSetPropertyForKey(_ ctx: JSContextRef!, _ object: JSObjectRef!, _ propertyKey: JSValueRef!, _ value: JSValueRef!, _ attributes: JSPropertyAttributes, _ exception: UnsafeMutablePointer<JSValueRef?>!)
```

## Parameters

`ctx`

The execution context to use.

`object`

The [`JSObjectRef`](/documentation/JavaScriptCore/JSObjectRef) with the property you want to set.

`propertyKey`

A [`JSValueRef`](/documentation/JavaScriptCore/JSValueRef) that contains the property key to use when looking up the property.

`value`

A [`JSValueRef`](/documentation/JavaScriptCore/JSValueRef) to use as the property’s value.

`attributes`

A set of [`JSPropertyAttributes`](/documentation/JavaScriptCore/JSPropertyAttributes) to give to the property.

`exception`

A pointer to a [`JSValueRef`](/documentation/JavaScriptCore/JSValueRef) to store an exception in, if any. Pass `NULL` to discard any exception.

## Discussion

This function is the same as performing `object[propertyKey] = value` from JavaScript.

---

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)