Set Item In List At Index | ARRAY_SET
Syntax
ARRAY_SET( [value], [index], [entry], [fill] = null )
Parameters
value
The array the value is being set in.
index
The index in the array to set the entry at.
The first index is 0.
If a negative value is provided, it is indexed from the end.
For example, the index -1 can be used to set the last value in the array.
entry
The value that will be inserted in the array at the index.
fill optional
A value to fill the array with if the provided index is greater than the current length of the array.
Return Value
An updated array with ENTRY set at the given INDEX within the VALUE is returned.Description
Sets a value in an array at a specified index. The operation creates a new array with the update and does not modify the original array.Examples
ARRAY_SET([1, 2, 3], 1, 4) # returns [1, 4, 3]
ARRAY_SET([1, 2, 3], -2, 4) # returns [1, 4, 3]
ARRAY_SET([1, 2, 3], 3, 4) # returns [1, 2, 3, 4]
ARRAY_SET([1, 2, 3], 5, 4) # returns [1, 2, 3, NULL, NULL, 4]
ARRAY_SET([1, 2, 3], 5, 4, "FILL") # returns [1, 2, 3, "FILL", "FILL", 4]
ARRAY_SET([1, 2, 3], -4, 4) # returns [1, 2, 3]
It can be used to generate a filled array of a given length.
ARRAY_SET([], 5, true, true) # returns [TRUE, TRUE, TRUE, TRUE, TRUE, TRUE]