Arrays: Introduction

An array is simply a list. We will declare an array with 3 messages:
var messages: Array=new Array("You can do it!","Keep up the good work!","Way to go!");
We now have an array names messages that has 3 items. The individual items in an array can be referred to using their position in the listing, starting with ZERO. Thus messages[0] is “You can do it!”
One of the reasons that arrays are so useful is that we can use a variable as the index instead of a constant. If n has a value of 2 then messages[n] is “Way to go!”
We could also have declared the array with no initial values:
var messages: Array=new Array();
We could then add values to the array by assigning a value:
messages[0]=”You can do it!”;
We can also add new items to the end of the list by using the push method:
messages.push("Good job!");

Please study the material at each of the links below.

  1. A Scrolling Message
  2. Message Changes
Like us on Facebook:

OER: Open Educational Resource
Creative Commons License Author: Janet E. Joy; Publisher:
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
Creative Commons Attribution-NonCommercial 4.0 International License
Last modified: May 23 2017 15:57:57.