Let's take a look at this example:
and compare it with this example:
In the first example, we use 5 different variables to store 5 different bits of information, and we then attach the value of each variable onto the string called vegtext which we can use or print out later.
This is great if you know how many bits you have, and you know their name.
In the second example, we use one variable which has been set as an array. We then use a loop to go through that array and attach the value of each onto the string called vegtext.
Arrays then, are great if you need to group lots of related information together, so you can either sort them (alphabetically, for example), or you need to be able to go through them in a loop.
<script>This simply sets your variable called veg to be an array, and includes it's values. This is great if you know the values at the time of setting the array, and you know how many there are.
<script>This simply sets your variable called veg to be an array, but includes no values. Then at any place in your script you can simpy push a new item into the veg array. You don't need to know how many items are already in the array, as push() simply adds new items to the bottom.
<script>This takes a string variable called myveg and splits in into parts using the the comma as a separator, and places those parts in an array called veg.
veg will now look exactly as it does in Examples 1, 2 & 3 above.
We don't need to tell veg to be an array first, as the split function does this for us.