array_shift_left()

Shifts the values inside a dynamic array to the left.

Syntax

array_shift_left(array, shift_count [, default_value ])

Learn more about syntax conventions.

Parameters

Name Type Required Description
array dynamic ✔️ The array to shift.
shift_count int ✔️ The number of positions that array elements are shifted to the left. If the value is negative, the elements are shifted to the right.
default_value scalar The value used for an element that was shifted and removed. The default is null or an empty string depending on the type of elements in the array.

Returns

Returns a dynamic array containing the same number of elements as in the original array. Each element has been shifted according to shift_count. New elements that are added in place of removed elements have a value of default_value.

Examples

Shifting to the left by two positions:

print arr=dynamic([1,2,3,4,5])
| extend arr_shift=array_shift_left(arr, 2)

Output

arr arr_shift
[1,2,3,4,5] [3,4,5,null,null]

Shifting to the left by two positions and adding default value:

print arr=dynamic([1,2,3,4,5])
| extend arr_shift=array_shift_left(arr, 2, -1)

Output

arr arr_shift
[1,2,3,4,5] [3,4,5,-1,-1]

Shifting to the right by two positions by using negative shift_count value:

print arr=dynamic([1,2,3,4,5])
| extend arr_shift=array_shift_left(arr, -2, -1)

Output

arr arr_shift
[1,2,3,4,5] [-1,-1,1,2,3]