I have a javascript array that is dynamically populated. Example: Array name $testarr[] And I have a database that fills it with numbers like this $testarr[id]=number. As my database is constantly growing I need to know when the array will hit the roof and refuse to take any more variables
-
6I put it to you that if you need to store this much data in JavaScript, you're doing something wrong and you should use Ajax lookups or server side pagination instead. (Provided you're talking about JavaScript in a browser. of course) – Pekka Oct 19 '11 at 19:22
-
1How many million items do you want to put there? I don't think there is a hard limit (well, maybe 2^53), I think the browsers and computers have different points at which they'll crash. – Michael Stum Oct 19 '11 at 19:23
-
1possible duplicate of [Maximum size of an Array in Javascript](http://stackoverflow.com/questions/6154989/maximum-size-of-an-array-in-javascript) – Wesley Murch Oct 19 '11 at 19:27
3 Answers
This is browser-specific, so you need to check with the browser documentation. There have actually been exploits that took advantage of this, as a large enough array would go beyond the maximum allowed to by the browser.
I believe your design is faulty, as if you need to hold this many variables in javascript, you should probably re-think your design.
EDIT: apparently there is a limit - 2^32 - 1 - but I believe you'll reach the limit imposed by the browser before you get to 2^32 - 1 elements in the array.

- 253,575
- 64
- 457
- 625
Apparently it is unlimited only by system memory, although the length
property fails if indices get larger than 1073741822 according to this source of 1997.

- 114,394
- 18
- 182
- 210
You're not dealing with a limitation of the Array
javascript object, you're dealing with the memory limitation of the browser/machine combo that is running your scripts.

- 61,812
- 21
- 118
- 158