=proto int duk_has_prop(duk_context *ctx, int obj_index); =stack [ ... obj! ... key! ] -> [ ... obj! ... ] =summary
Check whether value at obj_index has a property key. key is removed from the stack. Return code and error throwing behavior:
The property existence check is equivalent to the Ecmascript expression:
key in obj
For semantics, see Property Accessors, The in operator, and [[HasProperty]] (P). Both the target value and the key are coerced:
If the key is a fixed string you can avoid one API call and use the duk_has_prop_string() variant. Similarly, if the key is an array index, you can use the duk_has_prop_index() variant.
=example int rc; duk_push_string(ctx, "myProperty"); if (duk_has_prop(ctx, -3)) { printf("obj has 'myProperty'\n"); } else { printf("obj does not have 'myProperty'\n"); } =tags property stack =seealso duk_has_prop_string duk_has_prop_index