=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:
obj_index
is not an object, throws an error.obj_index
is invalid, throws an error.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:
String
and you can check for its
"length"
property.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.
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.