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:-
Instead ofCode:<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>
You can make (Untested)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";
And call it with something like this:-Code:var msg = new Array("msg1","msg2","msg3","msg4","msg5","msg6","msg7","msg8");
Explanation:-Code:<BODY onLoad="array_use()">
This is a Loop that will display a msg and increase i by one every time and it will go on until i<8Code:for (i=0; i<8; i++) { alert(msg[i]); }
A Preview:-
Conclusion:-
As Always Feedback is welcome and the full source is attached!!
Last edited by TcM; 06-26-2008 at 11:30 AM.
What else can you do with arrays? I have used them in coursework but the examples are lame - like amount of books borrowed from a library that are printed to the document for the user to view. wow. ground breaking stuff? methinks not.
Thanks to share this information,good information about how we can use array in <head> tag
These tutorials are not about efficiency, but about getting the basic thing and the concept of it into the readers mind.
Yeah, but makes it harder for someone trying to learn the concept of Arrays.
But as Arrays start with 0 and not with 1, if you don't make those indices, they might get confused. And they will not understand the concept of
Code:alert(msg[i]);
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks