--- id: 56bbb991ad1ed5201cd392cc title: Manipulate Arrays With pop() challengeType: 1 videoUrl: '' localeTitle: 使用pop()操作数组 --- ## Description
更改数组中数据的另一种方法是使用.pop()函数。 .pop()用于“弹出”数组末尾的值。我们可以通过将其赋值给变量来存储这个“弹出”值。换句话说, .pop()从数组中删除最后一个元素并返回该元素。任何类型的条目都可以从数组“弹出” - 数字,字符串,甚至嵌套数组。
var threeArr = [1, 4, 6];
var oneDown = threeArr.pop();
console.log(oneDown); // Returns 6
console.log(threeArr); // Returns [1, 4]
## Instructions
使用.pop()函数从myArray删除最后一项,将“弹出”值分配给removedFromMyArray
## Tests
```yml tests: - text: 'myArray应该只包含[["John", 23]] 。' testString: 'assert((function(d){if(d[0][0] == "John" && d[0][1] === 23 && d[1] == undefined){return true;}else{return false;}})(myArray), "myArray should only contain [["John", 23]].");' - text: 在myArray上使用pop() testString: 'assert(/removedFromMyArray\s*=\s*myArray\s*.\s*pop\s*(\s*)/.test(code), "Use pop() on myArray");' - text: 'removedFromMyArray应该只包含["cat", 2] 。' testString: 'assert((function(d){if(d[0] == "cat" && d[1] === 2 && d[2] == undefined){return true;}else{return false;}})(removedFromMyArray), "removedFromMyArray should only contain ["cat", 2].");' ```
## Challenge Seed
```js // Example var ourArray = [1,2,3]; var removedFromOurArray = ourArray.pop(); // removedFromOurArray now equals 3, and ourArray now equals [1,2] // Setup var myArray = [["John", 23], ["cat", 2]]; // Only change code below this line. var removedFromMyArray; ```
### After Test
```js console.info('after the test'); ```
## Solution
```js // solution required ```