=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:

Without 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.

=example duk_enum(ctx, -3, DUK_ENUM_INCLUDE_NONENUMERABLE); while (duk_next(ctx, -1 /*enum_index*/, 0 /*get_value*/)) { /* [ ... enum key ] */ printf("-> key %s\n", duk_get_string(ctx, -1)); duk_pop(ctx); } duk_pop(ctx); /* pop enum object */ =tags object property =seealso duk_next