2021-06-15 00:49:18 -07:00
---
id: cf1111c1c11feddfaeb8bdef
2021-07-21 20:53:20 +05:30
title: Modificar dados de array com índices
2021-06-15 00:49:18 -07:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/czQM4A8'
forumTopicId: 18241
dashedName: modify-array-data-with-indexes
---
# --description--
2021-11-03 08:22:32 -07:00
Ao contrário das strings, as entradas de arrays são < dfn > mutáveis</ dfn > e podem ser alteradas livremente, mesmo se o array foi declarado com `const` .
2021-06-15 00:49:18 -07:00
2021-07-14 21:02:51 +05:30
**Exemplo**
2021-06-15 00:49:18 -07:00
```js
2021-11-03 08:22:32 -07:00
const ourArray = [50, 40, 30];
2021-06-15 00:49:18 -07:00
ourArray[0] = 15;
```
2021-07-14 21:02:51 +05:30
`ourArray` agora tem o valor `[15, 40, 30]` .
2021-06-15 00:49:18 -07:00
2021-07-30 01:41:44 +09:00
**Observação:** não deve haver espaços entre o nome do array e os colchetes, como `array [0]` . Embora JavaScript seja capaz de processar isso corretamente, isso pode confundir outros programadores lendo seu código.
2021-06-15 00:49:18 -07:00
# --instructions--
2021-07-14 21:02:51 +05:30
Modifique o dado armazenado no índice `0` de `myArray` para um valor de `45` .
2021-06-15 00:49:18 -07:00
# --hints--
2021-11-03 08:22:32 -07:00
`myArray` agora deve ser `[45, 64, 99]` .
2021-06-15 00:49:18 -07:00
```js
assert(
(function () {
if (
typeof myArray != 'undefined' & &
myArray[0] == 45 & &
myArray[1] == 64 & &
myArray[2] == 99
) {
return true;
} else {
return false;
}
})()
);
```
2021-07-14 21:02:51 +05:30
Você deve usar o índice correto para modificar o valor em `myArray` .
2021-06-15 00:49:18 -07: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-11-03 08:22:32 -07:00
const myArray = [18, 64, 99];
2021-06-15 00:49:18 -07:00
// Only change code below this line
2021-11-03 08:22:32 -07:00
2021-06-15 00:49:18 -07:00
```
# --solutions--
```js
2021-11-03 08:22:32 -07:00
const myArray = [18, 64, 99];
2021-06-15 00:49:18 -07:00
myArray[0] = 45;
```