name: duk_replace proto: | void duk_replace(duk_context *ctx, duk_idx_t to_idx); stack: | [ ... old(to_idx)! ... val! ] -> [ ... val(to_idx)! ... ] summary: |

Replace value at to_idx with a value popped from the stack top. If to_idx 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_replace(ctx, -3); /* -> [ 123 "foo" 345 ] */ tags: - stack seealso: - duk_insert introduced: 1.0.0