We already know that an array is a better way of storing several related values than creating multiple variables. But what if we want to store several characteristics for each element in an array? Well, we can use two dimensional arrays for that! Watch the video below to find out more and then scroll down to see the code.
In the example code below, we have a two dimensional array that stores several people in an the array. For each person, the array also stores characteristics about them including their name, age, and gender. In other words, there are elements inside elements in the array.
If we wanted to access the first element in an array we would usually use the code arrayname. If we want to access the first element inside the first element of the array, we would access it using the code arrayname. Basically, there are two dimensions in the array. We access the first element in the first dimension, and the first element from its second dimension.
Check out the code below to see how you can create a 2D array, access elements inside it, and modify values in the array.
The code above will produce output that looks like this:
Next tutorial: If statements