Javascript Tutorials
Introduction to AJAX
Javascript Form Validation
Javascript Fundamentals

Javascript Fundamentals

Arrays

Arrays are data structures used for holding a collection of information. To declare an array use var arrayName = new array (<number of elements>);. var arrayName = new array (4); creates an array with four elements. Elements of arrays can be accessed via arrayName[<element number>]. Element numbering starts with 0 not 1.

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript_1.2">
arrayName[0]="String";
arrayName[1]=1234;
arrayName[2]=232.23;
arrayName[3]=arrayName[1]+arrayName[2];
</SCRIPT>

Sets the cells of arrayName to "String", 1234, 232.23, and 1466.23 respectively.

Associative Arrays

Another type of array that uses names instead of numbers to index elements. Associative arrays are created like regular arrays with the assocName = new Array();. Then to fill cells of the associative array do assocName["<cell name>"] = <value>;.

<SCRIPT TYPE="text/javascript" LANGUAGE="Javascript_1.2">
assocName = new Array(); assocName["Name"]="Jon";
assocName["Address"]="1 Fake St"
assocName["City"]="Atlanta";
assocName["State"]="GA";
assocName["Zipcode"]="30060";
</SCRIPT>

Creates the array assocName and sets the value Jon in Name, 1 Fake St in Address, City is set to Atlanta, State is set to GA, and Zipcode is set to 30060.

Basics <<  1 2 3 4 5  >> Objects and Classes
New Content