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!!