JavaScript Basics :
ARRAYS








When working with more complex scripts you might face a situation in which you would have many more or less
similar variables.

Instead of being forced to write a line for each operation
done to such a variable, you can use arrays to help you automate the process.

Consider this example:
Example 1Example 2
value1=10;
value2=20;
value3=30;
....
here would go 96 similar lines
....
value100=1000
value=new Array;
for (number=1; number<=100; number=number+1)
{ value[number]=number*10};


In example 1 you would need to enter 100 lines to perform an operation on your variables.

In example 2 you only need to enter 3 lines no matter how many variables you have.




An array must be defined before referring to any of the
variables in it.

This is done using the syntax: variablename=new Array;

Replace variblename with the desired name of your array.

Note: new must be written in small letters and Array must start with a capital A.




As the example indicated, arrays become extremely powerful when used in combination with loops.

However, you don't have to handle array variables in loops.

Single variables can be addressed with a syntax like this:

value[9]=170;






Congratulations!

You have reached the end of the tutorial!

When you feel comfortable with the basic javascript explained
in this section you should continue by learning about the
javascript objects.

Objects are predefined functions for maths, text variables, browser controlling, etc.

As a matter of fact each and every item placed on a webpage is an object that can be changed, read, or written to by javascript.

This is where the real fun starts with javascript: When you start controlling the single objects (form fields, buttons, images, menus, etc. etc.) on the pages.

That is where you really start taking your pages beyond
the average.

You can click here to explore the power of the javascript
built-in objects.

 << PREVIOUS
BACK TO MENU >>  
















DEVELOPER TIP!





     "Better Than Books - As Easy As It Gets!"