An array lets you manage a whole train of data

So far, you've used variables to store only a single piece of data. But sometimes, you want to refer to a whole bunch of data all at once. For that, you need a new type of variable: the array.

An array is a "collection variable" or data structure. It's designed to group a whole bunch of data items together in one place and give them

Think of an array as a data train. Each car in the train is called an array element and can store a single piece of data. If you want to store a number in one element and a string in another, you can.

Here comes the data train-

You might think that as you are storing all of that data in an array, you still might need variables for each of the items it stores. But this is not the case. An array is itself just another variable, and you can give it its own variable name:

my array = [7, "24", "Fish", "hat stand"]

my array = [7, "24", "Fish", "hat stand"]

Even though an array contains a whole bunch of data items, the array itself is a single variable, which just so happens to contain a collection of data. Once your data is in an array, you can treat the array just like any other variable.

So how do you use arrays?

a name.

create and extend an array

Was this article helpful?

0 0

Post a comment