2021-02-06 04:42:36 +00:00
---
id: 56bbb991ad1ed5201cd392cc
2021-03-07 09:15:14 -07:00
title: Manipula arreglos con pop()
2021-02-06 04:42:36 +00:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/cRbVZAB'
forumTopicId: 18236
dashedName: manipulate-arrays-with-pop
---
# --description--
2021-03-07 09:15:14 -07:00
Otra manera de cambiar los datos en un arreglo es con la función `.pop()` .
2021-02-06 04:42:36 +00:00
2021-03-07 09:15:14 -07:00
`.pop()` se utiliza para sacar un valor del final de un arreglo. Podemos almacenar este valor sacado asignándolo a una variable. En otras palabras, `.pop()` elimina el último elemento de un arreglo y devuelve ese elemento.
2021-02-06 04:42:36 +00:00
2021-03-07 09:15:14 -07:00
Cualquier tipo de entrada puede ser sacada de un arreglo: números, cadenas, incluso arreglos anidados.
2021-02-06 04:42:36 +00:00
```js
2021-10-31 23:08:44 -07:00
const threeArr = [1, 4, 6];
const oneDown = threeArr.pop();
2021-03-07 09:15:14 -07:00
console.log(oneDown);
console.log(threeArr);
2021-02-06 04:42:36 +00:00
```
2021-03-07 09:15:14 -07:00
El primer `console.log` mostrará el valor `6` y el segundo mostrará el valor `[1, 4]` .
2021-02-06 04:42:36 +00:00
# --instructions--
2021-10-31 23:08:44 -07:00
Utiliza la función `.pop()` para eliminar el último elemento de `myArray` , y asigna el valor sacado a un variable nuevo `removedFromMyArray` .
2021-02-06 04:42:36 +00:00
# --hints--
2021-03-07 09:15:14 -07:00
`myArray` sólo debe contener `[["John", 23]]` .
2021-02-06 04:42:36 +00:00
```js
assert(
(function (d) {
if (d[0][0] == 'John' & & d[0][1] === 23 & & d[1] == undefined) {
return true;
} else {
return false;
}
})(myArray)
);
```
2021-03-07 09:15:14 -07:00
Debes usar `pop()` en `myArray` .
2021-02-06 04:42:36 +00:00
```js
assert(/removedFromMyArray\s*=\s*myArray\s*.\s*pop\s*(\s*)/.test(code));
```
2021-03-07 09:15:14 -07:00
`removedFromMyArray` sólo debe contener `["cat", 2]` .
2021-02-06 04:42:36 +00:00
```js
assert(
(function (d) {
if (d[0] == 'cat' & & d[1] === 2 & & d[2] == undefined) {
return true;
} else {
return false;
}
})(removedFromMyArray)
);
```
# --seed--
## --after-user-code--
```js
2021-10-31 23:08:44 -07:00
if (typeof removedFromMyArray !== 'undefined') (function(y, z){return 'myArray = ' + JSON.stringify(y) + ' & removedFromMyArray = ' + JSON.stringify(z);})(myArray, removedFromMyArray);
2021-02-06 04:42:36 +00:00
```
## --seed-contents--
```js
// Setup
2021-10-31 23:08:44 -07:00
const myArray = [["John", 23], ["cat", 2]];
2021-02-06 04:42:36 +00:00
// Only change code below this line
2021-10-31 23:08:44 -07:00
2021-02-06 04:42:36 +00:00
```
# --solutions--
```js
2021-10-31 23:08:44 -07:00
const myArray = [["John", 23], ["cat", 2]];
const removedFromMyArray = myArray.pop();
2021-02-06 04:42:36 +00:00
```