views:

71

answers:

2

I'm trying to import a set of coordinates from an external javascript. I have to include about 78.740 elements in the constructor, but firefox just throws an error:
"too many constructor arguments"
Does anybody have any ideas?

This is my code:

function CreateArray() {   
return new Array(
...
...
...
78.740 elements later
...
); }
+1  A: 

You may be running into memory limitations, not sure.

How about trying to push() the values into an array instead of initializing all of them all at once? Break it into smaller chunks of data to add to the array instead of adding it all in one command.

var a = [];
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
a.push(1,2,3,4,5,6,7,8,9,10);
// etc...
return a;
Tauren
+7  A: 

Try array literal, it worked for me (tested with success for million items):

function CreateArray() {   
    return [
        ...
    ];
}
pepkin88
Gah, I type too slow. :-)
T.J. Crowder
+1 Side note, max array length is 4,294,967,295 but doubt anyone will reach that ^^
BGerrissen
with 2,000,000 items Firefox threw exception "script stack space quota is exhausted"
pepkin88
max length will vary each browser obviously ;)
BGerrissen
thanks, that worked
alex