2

I am creating Array() in javascript with 80000 elements Like

var arrRecWorkOrderNo = Array(1,2,3,,,,,,,,,,,,80000);

But unfortunately Iam getting an error: Uncaught SyntaxError: Too many arguments in function call (only 32766 allowed)

How can I solve that?

5
  • do u know about browser leaking memory ?? Commented Jun 20, 2013 at 5:50
  • 1
    Why not create an array with 80000 elements and use a for loop to populate index i with the value i+1 for i = 0; i < 80000; ++i? Commented Jun 20, 2013 at 5:50
  • @Patashu—what would it iterate over, an array? :-) Commented Jun 20, 2013 at 6:06
  • @RobG You can't pre-create an array of 80000 elements all with default value in Javascript? (I am not a Javascript coder) Commented Jun 20, 2013 at 6:07
  • @Patashu—Javascript arrays are just objects, they only have elements if they are created individually. E.g. var a = new Array(20) creates an array with a length of 20 and no members, e.g. '0' in a == false. Commented Jun 20, 2013 at 23:10

2 Answers 2

7

Don't use Array, just define it as:

var arrRecWorkOrderNo = [1,2,3,,,,,,,,,,,,80000];

Javascript has a limit of 32766 (signed short) when you put it as arguments to a constructor.

Sign up to request clarification or add additional context in comments.

2 Comments

Actually, this is way better than my answer, duh. Deleting my answer.
That's an array initialiser or array literal.
0

Don't use Array constructor, see Ken's answer for the right usage. Array constructor has weird behavior when called with arguments.

However, if you ever need to have more than 32766 arguments in a function (There is no excuse for that, really), you do something like:

var a = Array.apply(null, [1,,,,,,,,,,,,,,80000];

apply function sets the first parameter as this objects and second parameter as arguments.

Note: This is just a proof of concept, no one should ever have that much parameters, just accept an array.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.