你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

array_shift_right()

将动态数组中的值向右移动。

语法

array_shift_right(arrayshift_count [,default_value ])

详细了解语法约定

参数

名称 类型 必需 说明
array dynamic ✔️ 要移动的数组。
shift_count int ✔️ 数组元素向右移动的位置数。 如果值为负值,则元素会向左移动。
default_value 标量 (scalar) 用于已移动和已移除的元素的值。 默认值为 null 或空字符串,具体取决于 array 中元素的类型。

返回

返回一个包含与原始数组相同元素数的动态数组。 每个元素均已根据 shift_count 进行了移动。 添加的新元素(而不是已删除的元素)的值为 default_value

示例

向右移动两个位置:

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

输出

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

向右移动两个位置并添加默认值:

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

输出

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

使用负 shift_count 值向左移动两个位置:

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

输出

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