What is the longest possible array?
new Array(Number.MAX_VALUE) // ERROR.

What is the longest possible array?
new Array(Number.MAX_VALUE) // ERROR.
I did a little searching but could not find a reference that stated what the max size number of elements could be. So I did a little testing on my own. I used a web page from www.w3schools.comOriginally Posted by DHTML Kitchen
If I use a number any higher than the one in bright blue in the above code (4,294,967,295) I would get the following error code in FoxFire:Code:<html> <body> <script type="text/javascript"> var arr = new Array(3) arr[0] = "John" arr[1] = "Andy" arr[2] = "Wendy" document.write("Original length: " + arr.length) document.write("<br />") arr.length=4294967295 document.write("New length: " + arr.length) </script> </body> </html>
Error: invalid array length
Source File: http://www.w3schools.com/jsref/tryit_view.asp
Line: 14
I tried it on 3 different computers with different amounts of RAM, with the same results.
But I don't think it would be a good ideal to use an array that size.
Even if each entry in an array that big were only one byte in size it would take way too long for the web page to download to be usable. If each entry were a lot larger it could easily exceed the entire space on your web hosting.
The practical limit is probably in the hundreds if not lower.
Stephen
Learn Modern JavaScript  http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
Don't forget to start your JavaScript code with"use strict";
which makes it easier to find errors in your code.
JS doesnt put a limit on the size of an array. The only restraint is that of the user's computer. No matter the amount of memory/processor speed that a computer has it will still have a set limit, and for most the # will be close to that which you found.
"konithomimo",
I think I found the reason for the limit of 4,294,967,295 elements in a javascript array. That is the max size of an interger (2,147,483,648 to 2,147,483,648)
That should explain it to you. Basically, unlike other programming languages JS only has one type of number. Other languages usually have more than one (integer,double,etc.)Javascript currently only has one number type, floatingpoint, which is encapsulated as the object type "Number". Evidently, the actual value is held in binary as an IEEE Standard 754 Double. The range therefore slightly exceeds ±1.7×10308. Integers can only be held accurately up to, I think, 53 bits plus sign, and numbers are only, at best, accurate to 1516 significant decimal digits. Note, however, that any integer from 0 up to 253 = 9,007,199,254,740,992 in magnitude should be stored exactly, but relatively few decimal fractions can be. Only the numbers obtainable from one of those integers by multiplying by 2N53 for any N in 1023 to +1023 can be held exactly. Check in detail, though.