-3

I am trying to fill an array but when I fill it more than a certain size it stops working.

Is there any size limit on arrays in JavaScript? Is it specified anywhere?

I'm interested in a general answer, but I've spotted it not working using chrome on Windows.

Benjamin Gruenbaum
  • 270,886
  • 87
  • 504
  • 504
suganya
  • 135
  • 3
  • 14
  • What do you *think* the limit is? Can you reproduce the issue in a jsfiddle? – Jamiec Feb 18 '15 at 14:54
  • 1
    How absolutely humongous are the arrays you're working with? Or is the problem maybe in some other piece of code? – Cerbrus Feb 18 '15 at 14:55
  • the maximum length of an array according to the ECMA-262 5th Edition specification is bound by an unsigned 32-bit integer due to the ToUint32 abstract operation, so the longest possible array could have 232-1 = 4,294,967,295 = 4.29 billion elements. Are you using more than that ? – AhmadAssaf Feb 18 '15 at 14:57

1 Answers1

1

The maximum length of an array is 4,294,967,295 - that is, the maximum unsigned 32-bit integer.

Testing in the browser console yields this result:

Screenshot: Array of size 4,294,967,295 works, but +1 length fails

If you're making arrays that big... you have problems. Problems like this guy from Computer Stupidities

At my previous job, we were porting a UNIX system to Windows NT using Microsoft VC++. A colleague of mine, that was in the process of porting his portion of the code, came to me, looking really upset.

  • Colleague: "Hey! I hate these Microsoft guys! What a rotten compiler! It only accepts 16,384 local variables in a function!
Community
  • 1
  • 1
Niet the Dark Absol
  • 320,036
  • 81
  • 464
  • 592