Array.shift
Array.shift
功能
删除并返回数组第一个元素。
语法
array.shift()
参数
无参数。
返回值
| 类型 | 说明 |
|---|---|
| Any/Empty | 数组非空时返回被删除的元素;空数组返回 Empty。 |
示例
items = [1, 2, 3] result = items.shift() // 输出:1 print result
注意事项
- 该方法会修改原数组。
删除并返回数组第一个元素。
array.shift()
无参数。
| 类型 | 说明 |
|---|---|
| Any/Empty | 数组非空时返回被删除的元素;空数组返回 Empty。 |
items = [1, 2, 3] result = items.shift() // 输出:1 print result