/    Sign up×
Community /Pin to ProfileBookmark

Populate JavaScript Array using Function

I have to populate a JavaScript array using ASP. Now, this shouldn’t be difficult, but because of the way I needed to lay out the page, the array cannot become filled until the end of the page, but the array need to be declared in the beginning. Therefore, I thought that filling the array using a function would suffice since the function can be implemented later on the page. Here is what I have so far:

[code=php]/* fill variables */
var arrDrivers = new Array();
call popDrivers(arrDrivers);
var arrTrucks = new Array();
call popTrucks(arrTrucks);
[/code]

Later in the page, I hae the functions laid out like so…

[code=php]function popDrivers(arrDrivers){
//The ASP outputs numerous lines like this…
arrDrivers[“6279″]=”John B. Doe”;
return arrDrivers();
}[/code]

Now, what am I doing wrong in trying to fill the arrays?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@MichaelMDec 09.2003 — Looks like you're treating the index of the array as if it were a string. JavaScript expects the index of an array to be an integer.

So

    arrDrivers["6279"]="John B. Doe";

Should be

    arrDrivers[6279]="John B. Doe";
Copy linkTweet thisAlerts:
@hismightinessauthorDec 09.2003 — Thanks! I didn't realize that I was doing that. Howevr, I am still getting an error that I was hoping this post would resolve.

It is:

Line: 33

Error: Object Expected

Line 33 is this line:
[code=php]var arrDrivers = new Array();[/code]
×

Success!

Help @hismightiness 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...