2021-02-06 04:42:36 +00:00
---
id: cf1111c1c11feddfaeb8bdef
2021-03-07 09:15:14 -07:00
title: Modifica los datos de un arreglo con índices
2021-02-06 04:42:36 +00:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/czQM4A8'
forumTopicId: 18241
dashedName: modify-array-data-with-indexes
---
# --description--
2021-10-31 23:08:44 -07:00
A diferencia de las cadenas, las entradas de los arreglos son < dfn > mutables</ dfn > y pueden cambiarse libremente, incluso si el arreglo fue declarado con `const` .
2021-02-06 04:42:36 +00:00
2021-03-07 09:15:14 -07:00
**Ejemplo**
2021-02-06 04:42:36 +00:00
```js
2021-10-31 23:08:44 -07:00
const ourArray = [50, 40, 30];
2021-03-07 09:15:14 -07:00
ourArray[0] = 15;
2021-02-06 04:42:36 +00:00
```
2021-03-07 09:15:14 -07:00
`ourArray` ahora tiene el valor `[15, 40, 30]` .
**Nota:** No debe haber espacios entre el nombre del arreglo y los corchetes, como `array [0]` . Aunque JavaScript pueda procesar esto correctamente, puedes confundir a otros programadores al leer tu código.
2021-02-06 04:42:36 +00:00
# --instructions--
2021-03-07 09:15:14 -07:00
Modifica los datos almacenados en el índice `0` de `myArray` a un valor de `45` .
2021-02-06 04:42:36 +00:00
# --hints--
2021-10-31 23:08:44 -07:00
`myArray` ahora debe ser `[45, 64, 99]` .
2021-02-06 04:42:36 +00:00
```js
assert(
(function () {
if (
typeof myArray != 'undefined' & &
myArray[0] == 45 & &
myArray[1] == 64 & &
myArray[2] == 99
) {
return true;
} else {
return false;
}
})()
);
```
2021-03-07 09:15:14 -07:00
Debes usar el índice correcto para modificar el valor en `myArray` .
2021-02-06 04:42:36 +00:00
```js
assert(
(function () {
if (code.match(/myArray\[0\]\s*=\s*/g)) {
return true;
} else {
return false;
}
})()
);
```
# --seed--
## --after-user-code--
```js
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
```
## --seed-contents--
```js
// Setup
2021-10-31 23:08:44 -07:00
const myArray = [18, 64, 99];
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 = [18, 64, 99];
2021-02-06 04:42:36 +00:00
myArray[0] = 45;
```