/    Sign up×
Community /Pin to ProfileBookmark

Initializing values of long arrays

Hi,

I am trying to initialize all the values of an array to 0. This is how I did it:

var clicked = new Array(6);

function begin()
{
var i = 0;
while(i < clicked.length)
{
clicked[i] = 0;
++i;
}
}

Is there something wrong with this? For some reason the statements within the loop will only execute once and then no code after that will execute. And I’m not even sure if the clicked[0] has been assigned the value because when I try to display it with a document.writeln() nothing happens.

I know this is supposed to be really simple, but any advice would be greatly appreciated.

Thanks

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@DJRobThaManauthorJul 29.2005 — In an interesting turn of events, the above code that was not working yesterday is kinda working today. The values have been assigned but I cannot acces them unless I do so from outside that function. This is okay for me because that's how I want to do it, but is there any reason for this?

Thanks again.
Copy linkTweet thisAlerts:
@CharlesJul 29.2005 — A more efficient version of that would be: clicked = [0, 0, 0, 0, 0, 0]
Copy linkTweet thisAlerts:
@DJRobThaManauthorJul 29.2005 — I know at the moment it would be, but I'm thinking of making it much larger. 6 was just a number I was testing with.
×

Success!

Help @DJRobThaMan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...