View Full Version : Lifecycle of an Array

10-22-2003, 02:59 PM

me problem is, that I want to use an Array to store data on it and use it lateron in serveral functions.
I declared an array like this:

<script language="JavaScript">
var i = 1 ;
var MeinArray = new Array(100);

Lateron I want to use this Array in another function, which I declared in the <HEAD> section.

It looks like:

function sammle(x)
var x;
/*document.write("bin drin");*/


if ( i == 100 )
document.write("HaltStop 100");
if ( MeinArray[i] == "Enter" )

Now, at runtime I get the answer that "MeinArray" is not definded
in this particlure function.

I knew, that variable must be declared as globol for to use it
in all "places". But I cant find any hint what's about array declarations. Is it possible to use the same array in several functions, whithout losing data?

Best Regards


10-22-2003, 06:11 PM
It's entirely possible. There SHOULD be no loss of data.
Do you think you could give us a link to the page in question?

10-22-2003, 07:16 PM
declare the array as the first thing inside your script tags, this will ensure that it is defoned before anything tries to acess it.

as i think you are doing this:

Trying to acess array

defining it

which should be the other way round.


10-23-2003, 03:29 AM
Where did you populate the array?
Maybe you access it before you populated it.

10-23-2003, 07:14 AM
thanks for Your time in spending to answers my Question.
With Your Help I found my mistakes. First, the was a logical
error , but the main reason, the script not work is, that I called the array, before I hat assigned it.

Thefore many thanks and
best regards


EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum