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


I understand this array:

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

→ 1

As 0 is 1, 1 is 2 etc.


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 :dizzy_face:


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;).


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];


→ 8


my notes:

Does that look right?


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

1 Like

Thank you BenGitter

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 :sunglasses:

@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. 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!

Nice … will check it out. Thanks :slight_smile:

1 Like

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

1 Like

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

1 Like