DEV Community

Annie Huynh
Annie Huynh

Posted on

Creating Arrays

Definition:

An array is used to store a list of values in a single variable.

Access by Index:
Each element in the array has an index. First element is at index 0, the next is at index 1, the following is at index 2 ...

To access elements of the array put the index in square brackets like this:

array[i]

Enter fullscreen mode Exit fullscreen mode

This is called access by index

Note: The position of the value does not match the index. The index starts at 0. Hence, a value in first position of the array is called using index 0.

*Arrays of Non-Numbers:
*

Arrays can be made of any objects - booleans, strings, etc.

Arrays of Arrays

You can put arrays in arrays these are called multidimensional arrays:

my_2d_array = [[1, 2, 3, 4, 5], ["Here", "are", "some", "strings"], [true, false]]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)