2018-10-10 18:03:03 -04:00
---
id: 56bbb991ad1ed5201cd392cd
title: Manipulate Arrays With shift()
challengeType: 1
2019-08-28 16:26:13 +03:00
videoUrl: https://scrimba.com/c/cRbVETW
forumTopicId: 18238
2018-10-10 18:03:03 -04:00
localeTitle: Манипулировать массивами с о сдвигом ()
---
## Description
2019-08-28 16:26:13 +03:00
< section id = 'description' >
< code > pop()< / code > всегда удаляет последний элемент массива. Что делать, если вы хотите удалить первый? Вот где < code > .shift()< / code > . Он работает так же, как < code > .pop()< / code > , за исключением того, что он удаляет первый элемент вместо последнего.
< / section >
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
< section id = 'instructions' >
Используйте < code > .shift()< / code > чтобы удалить первый элемент из < code > myArray< / code > , присвоив значение «shifted off» < code > removedFromMyArray< / code > .
< / section >
2018-10-10 18:03:03 -04:00
## Tests
< section id = 'tests' >
```yml
tests:
2019-08-28 16:26:13 +03:00
- text: < code > myArray</ code > should now equal < code > [["dog", 3]]</ code > .
testString: assert((function(d){if(d[0][0] == 'dog' & & d[0][1] === 3 & & d[1] == undefined){return true;}else{return false;}})(myArray));
- text: < code > removedFromMyArray</ code > should contain < code > ["John", 23]</ code > .
testString: assert((function(d){if(d[0] == 'John' & & d[1] === 23 & & typeof removedFromMyArray === 'object'){return true;}else{return false;}})(removedFromMyArray));
2018-10-10 18:03:03 -04:00
```
< / section >
## Challenge Seed
< section id = 'challengeSeed' >
< div id = 'js-seed' >
```js
// Example
var ourArray = ["Stimpson", "J", ["cat"]];
var removedFromOurArray = ourArray.shift();
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].
// Setup
var myArray = [["John", 23], ["dog", 3]];
// Only change code below this line.
var removedFromMyArray;
```
< / div >
2019-08-28 16:26:13 +03:00
### After Tests
2018-10-10 18:03:03 -04:00
< div id = 'js-teardown' >
```js
2019-08-28 16:26:13 +03:00
(function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);
2018-10-10 18:03:03 -04:00
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2019-08-28 16:26:13 +03:00
var myArray = [["John", 23], ["dog", 3]];
// Only change code below this line.
var removedFromMyArray = myArray.shift();
2018-10-10 18:03:03 -04:00
```
2019-08-28 16:26:13 +03:00
2018-10-10 18:03:03 -04:00
< / section >