2018-09-30 23:01:58 +01:00
---
id: cf1111c1c11feddfaeb8bdef
title: Modify Array Data With Indexes
challengeType: 1
2019-02-14 12:24:02 -05:00
videoUrl: 'https://scrimba.com/c/czQM4A8'
2019-07-31 11:32:23 -07:00
forumTopicId: 18241
2018-09-30 23:01:58 +01:00
---
2020-11-27 19:02:05 +01:00
# --description--
2018-09-30 23:01:58 +01:00
Unlike strings, the entries of arrays are < dfn > mutable< / dfn > and can be changed freely.
2020-11-27 19:02:05 +01:00
**Example**
2019-05-17 06:20:30 -07:00
```js
var ourArray = [50,40,30];
ourArray[0] = 15; // equals [15,40,30]
```
2020-11-27 19:02:05 +01:00
**Note**
There shouldn't be any spaces between the array name and the square brackets, like `array [0]` . Although JavaScript is able to process this correctly, this may confuse other programmers reading your code.
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --instructions--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
Modify the data stored at index `0` of `myArray` to a value of `45` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --hints--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
`myArray` should now be [45,64,99].
2018-09-30 23:01:58 +01:00
```js
2020-11-27 19:02:05 +01:00
assert(
(function () {
if (
typeof myArray != 'undefined' & &
myArray[0] == 45 & &
myArray[1] == 64 & &
myArray[2] == 99
) {
return true;
} else {
return false;
}
})()
);
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
You should be using correct index to modify the value in `myArray` .
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
assert(
(function () {
if (code.match(/myArray\[0\]\s*=\s*/g)) {
return true;
} else {
return false;
}
})()
);
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
# --seed--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
## --after-user-code--
2018-09-30 23:01:58 +01:00
```js
2018-10-20 21:02:47 +03:00
if(typeof myArray !== "undefined"){(function(){return myArray;})();}
2018-09-30 23:01:58 +01:00
```
2020-11-27 19:02:05 +01:00
## --seed-contents--
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
```js
// Setup
var myArray = [18,64,99];
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
// Only change code below this line
```
2018-09-30 23:01:58 +01:00
2020-11-27 19:02:05 +01:00
# --solutions--
2018-09-30 23:01:58 +01:00
```js
var myArray = [18,64,99];
myArray[0] = 45;
```