# Access Array Data with Indexes then Modify Array Data With Indexes?

**URL:** <https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180>\
**Category:** General\
**Created:** [September 29, 2016, 10:08am UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180 "2016-09-29T10:08:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nigelFrancisNET](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nigelfrancisnet/32/158888_2.png) [@nigelFrancisNET](https://forum.freecodecamp.org/u/nigelFrancisNET)\
**Post date:** [September 29, 2016, 10:08am UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/1 "2016-09-29T10:08:38Z")

</div>

Hi,

I understand this array:

```
var myArray = [1,2,3];
var myData = myArray[0]; 

```

→ 1

As 0 is 1, 1 is 2 etc.

BUT…

```
var myArray = [1, 2, 3];
myArray[0] = 3;

```

→ 3,2,3

Where does that come from please?

I need to understand that before I’m able to move onto - **Access MultiDimensional Arrays With Indexes** 😵

Nigel

---

<div class="post-metadata">

**Author:** ![BenGitter](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bengitter/32/12192_2.png) [@BenGitter](https://forum.freecodecamp.org/u/BenGitter)\
**Post date:** [September 29, 2016, 10:15am UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/2 "2016-09-29T10:15:25Z")

</div>

```
var myArray = [1, 2, 3];
myArray[0] = 3;

```

First you set the array with 3 values. Then you say: change the first value (index 0) to a value of 3.

So you can acces a value of an element in an array (`var myData = myArray[0];` or `console.log(myArray[0]);`), or change the value of an element in an array (`myArray[0] = 3;`).

---

<div class="post-metadata">

**Author:** ![nigelFrancisNET](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nigelfrancisnet/32/158888_2.png) [@nigelFrancisNET](https://forum.freecodecamp.org/u/nigelFrancisNET)\
**Post date:** [September 29, 2016, 11:03am UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/3 "2016-09-29T11:03:12Z")

</div>

Many thanks. Perhaps I’d lost it in FFC’s explanation somewhere?

NOW… please don’t go away!

I thought, once I knew that, I’d understand the next challenge… wishful thinking!

```
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];

var myData = myArray[0][0]; // this is to equal 8

```

But before replying to your good self, I looked at it again.

And came up with:

```
var myData = myArray[2][1];

document.write(myArray[2][1]);

```

→ 8

🙂🙂🙂🙂

my notes:

 ![](https://global.discourse-cdn.com/freecodecamp/original/3X/7/d/7d9354d530f6820cf3759a4049335c3e31404adc.PNG)

Does that look right?

---

<div class="post-metadata">

**Author:** ![BenGitter](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/bengitter/32/12192_2.png) [@BenGitter](https://forum.freecodecamp.org/u/BenGitter)\
**Post date:** [September 29, 2016, 12:57pm UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/4 "2016-09-29T12:57:57Z")

</div>

They should include that in the challenge! This is a very clear explanation of nested arrays.

---

<div class="post-metadata">

**Author:** ![nigelFrancisNET](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nigelfrancisnet/32/158888_2.png) [@nigelFrancisNET](https://forum.freecodecamp.org/u/nigelFrancisNET)\
**Post date:** [September 29, 2016, 1:03pm UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/5 "2016-09-29T13:03:52Z")

</div>

Thank you BenGitter [https://twitter.com/nigelfrancisnet/status/781478175515836416](https://twitter.com/nigelfrancisnet/status/781478175515836416)

Considering I was scratching my head with the first one, which in itself was/is easy… yes the explanation could be better.

Once again, thanks 🕶

---

<div class="post-metadata">

**Author:** ![Ailokin](https://avatars.discourse-cdn.com/v4/letter/a/7ab992/32.png) [@Ailokin](https://forum.freecodecamp.org/u/Ailokin)\
**Post date:** [September 29, 2016, 1:28pm UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/6 "2016-09-29T13:28:17Z")

</div>

@nigelFrancisNET: If you haven’t yet checked out MDN’s JavaScript documentation, you might find that helpful, as well. There’s an indexed collection in their [JavaScript Guides on arrays](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections). The whole page is helpful, and if you scroll down, you’ll see a discussion of multi-dimensional arrays with a chart that shows how indexing works. Hope this helps!

---

<div class="post-metadata">

**Author:** ![nigelFrancisNET](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/nigelfrancisnet/32/158888_2.png) [@nigelFrancisNET](https://forum.freecodecamp.org/u/nigelFrancisNET)\
**Post date:** [October 1, 2016, 8:11am UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/7 "2016-10-01T08:11:34Z")

</div>

Nice … will check it out. Thanks 🙂

---

<div class="post-metadata">

**Author:** ![char502](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/char502/32/43875_2.png) [@char502](https://forum.freecodecamp.org/u/char502)\
**Post date:** [May 19, 2017, 2:25pm UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/8 "2017-05-19T14:25:46Z")

</div>

Thanks for these notes Nigel, this was confusing me until i saw this, now it is much clearer 🙂

---

<div class="post-metadata">

**Author:** ![denmant](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/denmant/32/71247_2.png) [@denmant](https://forum.freecodecamp.org/u/denmant)\
**Post date:** [November 15, 2017, 10:48am UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/9 "2017-11-15T10:48:15Z")

</div>

Nigel, Thank you for the explanation!! Worked for me!!

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 1:09pm UTC](https://forum.freecodecamp.org/t/access-array-data-with-indexes-then-modify-array-data-with-indexes/41180/11 "2021-01-16T13:09:10Z")

</div>

Closed on January 16, 2021, 1:09pm UTC


