=proto int duk_del_prop(duk_context *ctx, int obj_index); =stack [ ... obj! ... key! ] -> [ ... obj! ... ] =summary

Delete the property key of a value at obj_index. key is removed from the stack. Return code and error throwing behavior:

The property deletion is equivalent to the Ecmascript expression:

delete obj[key]

For semantics, see Property Accessors, The delete operator and [[Delete]] (P, Throw). The return value and error throwing behavior mirrors the Ecmascript delete operator behavior. Both the target value and the key are coerced:

This API call returns non-zero when the target property does not exist. This is not very intuitive, but follows Ecmascript semantics: delete obj.nonexistent also evaluates to true.
At the moment all Duktape/C functions are strict. When called from a Duktape/C function, this API call thus either returns non-zero or throws an error. However, if called outside a Duktape/C function (when the context has an empty call stack) the API call executes in non-strict mode, i.e. returns 0 when trying to delete a non-configurable property.

If the key is a fixed string you can avoid one API call and use the duk_del_prop_string() variant. Similarly, if the key is an array index, you can use the duk_del_prop_index() variant.

=example int rc; duk_push_string(ctx, "myProperty"); rc = duk_del_prop(ctx, -3); printf("delete obj.myProperty -> rc=%d\n", rc); =tags property =seealso duk_del_prop_string duk_del_prop_index