alex
alex

Reputation: 1278

javascript too many constructor arguments

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
...
); }

Upvotes: 6

Views: 858

Answers (2)

pepkin88
pepkin88

Reputation: 2756

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

function CreateArray() {   
    return [
        ...
    ];
}

Upvotes: 9

Tauren
Tauren

Reputation: 27235

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;

Upvotes: 1

Related Questions