global variables with javascript

BearX00

Senior member
Nov 28, 2000
208
0
0
How do i make a global array in javascript so that it can be seen from function to function. more importantly i need the state to exist throughout different iterations of one certain function.
 

RedRooster

Diamond Member
Sep 14, 2000
6,596
0
76
If you've got all your functions in one block, then just declare the array immediately after the <SCRIPT> tag, and before the first function.
ie.
<SCRIPT LANGUAGE=JavaScript>
globalarray = new Array(5);

function -----
function -----
</SCRIPT>

It'll hold it's values all the time, and they can be changed and accessed from any function.
Hope that helps.