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:
1
.1
(not 0).obj_index
is not
object coercible,
throws an error.obj_index
is invalid, throws an error.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:
key
argument is internally coerced to a string. There is
an internal fast path for arrays and numeric indices which avoids an
explicit string coercion, so use a numeric key
when applicable.
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.