View Single Post
  #1 (permalink)  
Old 12-03-2006, 09:52 AM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 7,232
Rep Power: 66
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default JavaScript:Tutorial, Using Arrays

Introduction:-
Usually this is a difficult thing when it comes to programming and usually people get mixed up with arrays.

Solution:-
Make this Function between the <head> tags:-

Code:
<SCRIPT language="JavaScript">

function array_use()
{

var msg= new Array(8)
msg[0]="Msg1";
msg[1]="Msg2";
msg[2]="Msg3";
msg[3]="Msg4";
msg[4]="Msg5";
msg[5]="Msg6";
msg[6]="Msg7";
msg[7]="Msg8";

var i=0;



for (i=0; i<8; i++)

  {
     alert(msg[i]);
  }

}

</SCRIPT>
Instead of

Code:
var msg= new Array(8)
msg[0]="Msg1";
msg[1]="Msg2";
msg[2]="Msg3";
msg[3]="Msg4";
msg[4]="Msg5";
msg[5]="Msg6";
msg[6]="Msg7";
msg[7]="Msg8";
You can make (Untested)

Code:
var msg = new Array("msg1","msg2","msg3","msg4","msg5","msg6","msg7","msg8");
And call it with something like this:-
Code:
<BODY onLoad="array_use()">
Explanation:-
Code:
for (i=0; i<8; i++)

  {
     alert(msg[i]);
  }
This is a Loop that will display a msg and increase i by one every time and it will go on until i<8

A Preview:-


Conclusion:-
As Always Feedback is welcome and the full source is attached!!
Attached Files To view attachments your post count must be 1 or greater. Your post count is 0 momentarily.

Last edited by TcM; 06-26-2008 at 01:30 PM.
Reply With Quote

Sponsored Links