=proto void duk_enum(duk_context *ctx, int obj_index, int enum_flags); =stack [ ... obj! ... ] -> [ ... obj! ... enum! ] =summary
Create an enumerator for object at obj_index
. Enumeration
details can be controlled with enum_flags
. If the target value
is not an object, throws an error.
Enumeration flags:
DUK_ENUM_INCLUDE_NONENUMERABLE
: enumerate also non-enumerable
properties (by default only enumerable properties are enumerated)DUK_ENUM_INCLUDE_INTERNAL
: enumerate also internal properties
(by default internal properties are not enumerated)DUK_ENUM_OWN_PROPERTIES_ONLY
: enumerate only an object's "own"
properties (by default also inherited properties are enumerated) DUK_ENUM_ARRAY_INDICES_ONLY
: enumerate only array indices,
i.e. property names of the form "0", "1", "2", etc.DUK_ENUM_SORT_ARRAY_INDICES
: sort array indices by their numeric
value, only use with DUK_ENUM_ARRAY_INDICES_ONLY
; this is quite
slowWithout any flags, enumeration follows the Ecmascript default enumeration semantics, as in the expression:
for (key in obj) { print(key, obj[i]); }
Once the enumerator has been created, use
duk_next()
to extract keys (or key/value
pairs) from the enumerator.