2018-10-08 13:34:43 -04:00
---
id: 56bbb991ad1ed5201cd392cd
title: Manipulate Arrays With shift()
challengeType: 1
2018-10-10 16:20:40 -04:00
videoUrl: ''
localeTitle: Manipular matrices con cambio ()
2018-10-08 13:34:43 -04:00
---
## Description
2018-10-10 16:20:40 -04:00
< section id = "description" > < code > pop()< / code > siempre elimina el último elemento de una matriz. ¿Qué pasa si quieres eliminar el primero? Ahí es donde < code > .shift()< / code > en < code > .shift()< / code > . Funciona igual que < code > .pop()< / code > , excepto que elimina el primer elemento en lugar del último. < / section >
2018-10-08 13:34:43 -04:00
## Instructions
2018-10-10 16:20:40 -04:00
< section id = "instructions" > Use la función < code > .shift()< / code > para eliminar el primer elemento de < code > myArray< / code > , asignando el valor " desviado" a < code > removedFromMyArray< / code > . < / section >
2018-10-08 13:34:43 -04:00
## Tests
< section id = 'tests' >
```yml
tests:
2018-10-10 16:20:40 -04:00
- text: '< code > myArray</ code > ahora debe ser igual a < code > [[" dog" , 3]]</ code > .'
2018-10-08 13:34:43 -04:00
testString: 'assert((function(d){if(d[0][0] == "dog" & & d[0][1] === 3 & & d[1] == undefined){return true;}else{return false;}})(myArray), "< code > myArray< / code > should now equal < code > [["dog", 3]]< / code > .");'
2018-10-10 16:20:40 -04:00
- text: '< code > removedFromMyArray</ code > debe contener < code > [" John" , 23]</ code > .'
2018-10-08 13:34:43 -04:00
testString: 'assert((function(d){if(d[0] == "John" & & d[1] === 23 & & typeof removedFromMyArray === "object"){return true;}else{return false;}})(removedFromMyArray), "< code > removedFromMyArray< / code > should contain < code > ["John", 23]< / code > .");'
```
< / 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 >
### After Test
< div id = 'js-teardown' >
```js
console.info('after the test');
```
< / div >
< / section >
## Solution
< section id = 'solution' >
```js
2018-10-10 16:20:40 -04:00
// solution required
2018-10-08 13:34:43 -04:00
```
< / section >