insert() Function

Inserts a value into the given array and returns the resulting array.

Syntax

insert( array, value, index )

array: (Any Type Array) The array to modify.

value: (Any Type or Any Type Array) The value or values to insert.

index: (Integer or Integer Array) The index or array of indices at which the value should be inserted.

Returns

Any Type Array

Notes

An index value less than 1 appends the value to the left-side of the array, and an index value greater than the array length appends the value to the right-side of the array.

Examples

You can experiment with this function in the test box below.

Test Input

insert({10, 20, 30, 40}, 100, 1) returns 100, 10, 20, 30, 40

insert({10, 20, 30, 40}, 100, 5) returns 10, 20, 30, 40, 100

insert({10, 20, 30, 40}, {100, 200}, 1) returns 100, 200, 10, 20, 30, 40

insert({10, 20, 30, 40}, 100, {1, 2}) returns 100, 10, 100, 20, 30, 40

insert({10, 20, 30, 40}, {100, 200}, {1, 2}) returns 100, 10, 200, 20, 30, 40

FEEDBACK