|
|
Arrays
Arrays are a very important part to managing data on a large scale.An array
is usually declared just like any other data type. Instead of containing one type
of value, it contains any number of values.Some programming languages require
you to specify the maximum length of your array.
Typically each element, or variable, of the array has the same data type.
Most programming languages only allow one type or another, some allow both. Usually languages that allow both will only have one array with the properties of both types.
Different kinds of arrays:
Standard/numeric array
Each element of the array is indexed, or identified, by a number.
Elements can be added at the begining or the end of an array and the index of the
items inside will change.
Generally considered to be the fastest and most effective form of array.
The first element's index is 0 by default
Example:
var Players = new Array("Ron", "Sarah", "Omar");
or
var Players = new Array();
Players[0] = "Ron";
Players[1] = "Sarah";
Players[2] = "Omar";
var Position = [200, 400]; |
Associative Array (also known as a hash table)
Each element is indexed with a string (sometimes called a key).
The index string must be specified when the array element is declared, otherwise the array will use a numeric index.
Although slower, this format of array allows you link multiple arrays more easily.
Example:
var ZipFiles = new Array();
var TxtFiles = new Array();
var ExeFiles = new Array();
var Files = new Array();
var Files["zip"] = ZipFiles;
var Files["txt"] = TxtFiles;
var Files["exe"] = ExeFiles;
var FileTypes = ["zip", "txt", "exe"]; |
|
|
|
Previous Page:
Data Types,
Next Page:
Objects. |
|