Quirrel4.41.0

types.Array.replace_with

Method on every array
array.replace_with(other: array): any

Overwrites this array's elements with other's.

The binding carries no declaration string, so the VM cannot report parameter names. The names above are from this page; the types and attributes still come from the VM. The VM also cannot tell an optional parameter from a variadic tail here, so read the brackets and any trailing ... from the prose below, not from the signature.

Parameters

otherarraythe array to copy elements from

Return value

This array.

Notes

The new length matches other, so this can grow or shrink the array, unlike apply. The elements themselves are copied by reference, the same as slice and clone: a table or array element ends up shared between this array and other afterward.

replace is a deprecated alias for this function.

Example

examples/types/array/replace_with.nut
let a = [1, 2, 3, 4];
let src = [7, 8];
let same = a.replace_with(src);
println("same == a:", same == a);     // returns this array
println("a.len() =", a.len());        // length now matches src, not the old length
println("a =", ", ".join(a.map(@(v) v.tostring())));
Output:
same == a: true
a.len() = 2
a = 7, 8

See also

cloneMakes a shallow copy of the array.
extendAppends every element of other to this array.
arrayclass index