2018-10-10 18:03:03 -04:00
---
id: 56bbb991ad1ed5201cd392ce
title: Manipulate Arrays With unshift()
challengeType: 1
2019-08-28 16:26:13 +03:00
videoUrl: https://scrimba.com/c/ckNDESv
forumTopicId: 18239
2018-10-10 18:03:03 -04:00
localeTitle: Манипулировать массивами С помощью функции unshift ()
---
## Description
2019-08-28 16:26:13 +03:00
<section id='description'>
Вы не только можете <code>shift</code> элементы с начала массива, но также можете <code>unshift</code> элементы в начало массива, то есть добавить элементы перед массивом. <code>.unshift()</code> работает точно так же, как <code>.push()</code> , но вместо добавления элемента в конце массива <code>unshift()</code> добавляет элемент в начале массива.
</section>
2018-10-10 18:03:03 -04:00
## Instructions
2019-08-28 16:26:13 +03:00
<section id='instructions'>
Добавьте <code>["Paul",35]</code> в начало переменной <code>myArray</code> используя <code>unshift()</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 have [["Paul", 35], ["dog", 3]].
testString: assert((function(d){if(typeof d[0] === "object" && d[0][0] == 'Paul' && d[0][1] === 35 && d[1][0] != undefined && d[1][0] == 'dog' && d[1][1] != undefined && d[1][1] == 3){return true;}else{return false;}})(myArray));
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"];
ourArray.shift(); // ourArray now equals ["J", "cat"]
ourArray.unshift("Happy");
// ourArray now equals ["Happy", "J", "cat"]
// Setup
var myArray = [["John", 23], ["dog", 3]];
myArray.shift();
// Only change code below this line.
```
</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);})(myArray);
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]];
myArray.shift();
myArray.unshift(["Paul", 35]);
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>