array_shift_left()array_shift_left()
将 dynamic
数组中的值向左移动。Shifts the values inside a dynamic
array to the left.
语法Syntax
array_shift_left(
arr
, shift_count
[,
fill_value
])
array_shift_left(
arr
, shift_count
[,
fill_value
])
参数Arguments
arr
:要拆分的输入数组,必须是动态数组。arr
: Input array to split, must be dynamic array.shift_count
:整数,用于指定数组元素将向左移动的位置数。shift_count
: Integer specifying the number of positions that array elements will be shifted to the left. 如果该值为负数,则元素将向右移动。If the value is negative, the elements will be shifted to the right.fill_value
:用于插入元素的标量值,而不是移动和删除的元素。fill_value
: Scalar value that is used for inserting elements instead of the ones that were shifted and removed. 默认值:null 值或空字符串(取决于arr
类型)。Default: null value or empty string (depending on thearr
type).
返回Returns
包含的元素数与原始数组中的元素数相同的动态数组。Dynamic array containing the same number of elements as in the original array. 每个元素均已根据 shift_count 进行了移动。Each element has been shifted according to shift_count. 为代替已删除元素而添加的新元素的值为 fill_value。New elements that are added in place of removed elements will have a value of fill_value.
请参阅See also
- 要向右移动数组,请参阅 array_shift_right()。For shifting array right, see array_shift_right().
- 要向右旋转数组,请参阅 array_rotate_right()。For rotating array right, see array_rotate_right().
- 要向左旋转数组,请参阅 array_rotate_left()。For rotating array left, see array_rotate_left().
示例Examples
向左移动两个位置:Shifting to the left by two positions:
print arr=dynamic([1,2,3,4,5]) | extend arr_shift=array_shift_left(arr, 2)
arr
arr_shift
[1,2,3,4,5][1,2,3,4,5] [3,4,5,null,null][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)
arr
arr_shift
[1,2,3,4,5][1,2,3,4,5] [3,4,5,-1,-1][3,4,5,-1,-1] 使用负 shift_count 值向右移动两个位置: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)
arr
arr_shift
[1,2,3,4,5][1,2,3,4,5] [-1,-1,1,2,3][-1,-1,1,2,3]