Deconstructing an Array
As stated earlier, an array is a data type that can hold multiple pieces of information. Here's an easy way to imagine this: A variable is like a chair, and it can hold one person (one piece of data). On the other hand, an array is more like a bench, it can hold multiple people (multiple pieces of data).Each piece of data in an array is called an element . Each element is automatically assigned the name of the array and a unique number called its index , which is enclosed in brackets. However, the first element in an array is not assigned the number 1; it is instead assigned the number 0 because arrays are zero-indexed meaning that they start counting at zero instead of one.Therefore, the first element in the array my_array is labeled my_array[0]. Likewise, for the seventh element in the same array, you would use my_array[6].This indexing is great for holding and retrieving sequential information.The number of elements in an array is known as its length , and we will cover this topic in greater detail later in the chapter when the properties of an array are discussed.