13 lines
370 B
Markdown
13 lines
370 B
Markdown
|
---
|
|||
|
title: Manipulate Arrays With shift()
|
|||
|
localeTitle: 使用shift()操纵数组
|
|||
|
---
|
|||
|
## 使用shift()操纵数组
|
|||
|
|
|||
|
虽然`pop()`用于删除数组的最后一个元素,但`shift()`用于删除第一个元素。这就像你将元素向下移动一个位置。看一下这个:
|
|||
|
|
|||
|
```javascript
|
|||
|
var arr = [1, 2, 3, 4, 5];
|
|||
|
arr.shift(); // Gets rid of the 1
|
|||
|
|
|||
|
```
|