Skip to content

Latest commit

 

History

History
84 lines (58 loc) · 2.93 KB

array-shift-right-function.md

File metadata and controls

84 lines (58 loc) · 2.93 KB
title description ms.reviewer ms.topic ms.date
array_shift_right()
Learn how to use the array_shift_right() function to shift values inside a dynamic array to the right.
alexans
reference
09/05/2023

array_shift_right()

Shifts the values inside a dynamic array to the right.

Syntax

array_shift_right(array, shift_count [, default_value ])

[!INCLUDE syntax-conventions-note]

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 right. If the value is negative, the elements are shifted to the left.
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 amount of the elements as in the original array. Each element has been shifted according to shift_count. New elements that are added instead of the removed elements have a value of default_value.

Examples

Shifting to the right by two positions:

[!div class="nextstepaction"] Run the query

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

Output

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

Shifting to the right by two positions and adding a default value:

[!div class="nextstepaction"] Run the query

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

Output

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

Shifting to the left by two positions by using a negative shift_count value:

[!div class="nextstepaction"] Run the query

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

Output

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

Related content