=proto void duk_insert(duk_context *ctx, int to_index); =stack [ ... old(to_index)! ... val! ] -> [ ... val(to_index)! old! ... ] =summary

Insert a value at to_index with a value popped from the stack top. The previous value at to_index and any values above it are moved up the stack by a step. If to_index is an invalid index, throws an error.

Negative indices are evaluated prior to popping the value at the stack top. This is also illustrated by the example.
=example duk_push_int(ctx, 123); duk_push_int(ctx, 234); duk_push_int(ctx, 345); /* -> [ 123 234 345 ] */ duk_push_string(ctx, "foo"); /* -> [ 123 234 345 "foo" ] */ duk_insert(ctx, -3); /* -> [ 123 "foo" 234 345 ] */ =tags stack =seealso duk_replace