name: duk_get_prop proto: | duk_bool_t duk_get_prop(duk_context *ctx, duk_idx_t obj_index); stack: | [ ... obj! ... key! ] -> [ ... obj! ... val! ] (if key exists) [ ... obj! ... key! ] -> [ ... obj! ... undefined! ] (if key doesn't exist) summary: |
Get the property key
of a value at obj_index
.
Return code and error throwing behavior:
1
is returned and key
is replaced by the property value on the value stack. However,
if the property is an accessor, the "getter" function may throw
an error.key
is replaced by undefined
on the value stack.obj_index
is not
object coercible,
throws an error.obj_index
is invalid, throws an error.The property read is equivalent to the Ecmascript expression:
obj[key]
For semantics, see
Property Accessors,
GetValue (V),
and [[Get]] (P).
Both the target value and the key
are coerced:
String
and you can access 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_get_prop_string()
variant.
Similarly, if the key is an array index, you can use the
duk_get_prop_index()
variant.