top of page
2D-array-representation.png
2D-array-representation.png

2D ARRAYS

A 2D Array is an array of arrays 

The imagine on the left is how you should imagine what a 2D array is. 

Initializing 2D Array 

There are two ways to initialize a 2D Array:

​

1. Add values automatically with the {} brackets

​

2. Create space and add the values in later

Access Elements

To access the elements of the 2D array, specify two indexes: one for the array, and one for the element inside that array. This example accesses the third element (2) in the second array (1) of example 1:

Will print 2.

Change Element Values

To change an element values in a 2D Array you would:

1. call the array element 

2. set it equal, =, to the element 

Capture.PNG

Loop Through a Multi-Dimensional Array

Lets say you wanted to print out every element in order from left to right. You would want to use a nested for loop. Look the the example above to see how it was done.

bottom of page