1 Javascript Array Thu Apr 12, 2012 12:12 am
Mr.Joker
Mr. WebArtz
Javascript Array Working with arrays in JavaScript |
Hello members of WebArtz, I am Mr.Joker and today I will try to teach you what is an Array. Well, as a name say allready an Array can store some values inside it. For example an array in real life example is : -Computer, Mouse, Desk , etc. So thats an Array. But what for we need an Array while coding. Well here is one example of Array:
Ok, lets explain a code. We have a variable movies but a value of that variable is a new Array. So I will add several values to single variables. Yes, it is possible because of arrays. In next line i write variable and inside this brackets i add a number 0 which mean that variable is the first one. Computer always count from 0 as you know allready. And now i add some value to that variable. In next row I add number 1 inside brackets which is a new value for variable movies. Now simple add another movie. And do the same for last movie Matrix. Now, If i want to write all 3 movies at once on the screen i can do that by writing document.write(movie[0] + "<br />") and 2 more times that for each movie but its wasting of time. I just simple use for loop and say that there is variable i with value zero. There is condition that say if variable i is less then 3 increase that variable value by the time till it become 3. Why 3? Its because i have 3 movies inside Array. Now i said while that loop exists i want to write document.write(movies[i] + break)... Why like this? Well as you know when variable i have starting value 0 it start to increase. I used that inside movies because i dont want to waste my time to write numbers each time. A computer will do that for me. Its so simple to understand how Array works. As i promesd I will explan you code i gived you in last tutorial which is this one:
Lets start. I declare a variable Rollimage and set it to new Array. When i write Rollimage[0] = new Image(); i say now that that variable have a value of image. And then in next row I use again same variable but with .src because i want to set a URL of image. Then i create another variable with value of image and set some URL for it again. Then i write a function called over because I want to declare what will happend if I use mouse over image. There I say:
|
Notice : These tutorials are copyrighted by WebArtz Forum. You may not publish it on anywhere without written permission from the administrators. |