name: duk_del_prop proto: | duk_bool_t duk_del_prop(duk_context *ctx, duk_idx_t 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 1 when the target property does not exist. This is not very intuitive, but follows Ecmascript semantics: delete obj.nonexistent also evaluates to true.

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: | duk_bool_t rc; duk_push_string(ctx, "myProperty"); rc = duk_del_prop(ctx, -3); printf("delete obj.myProperty -> rc=%d\n", (int) rc); tags: - property seealso: - duk_del_prop_string - duk_del_prop_index introduced: 1.0.0