Enjoy an ad free experience by logging in. Not a member yet? Register.

Results 1 to 6 of 6
Thread: Array max length?

01012006, 01:59 AM #1
 Join Date
 Mar 2004
 Posts
 130
 Thanks
 0
 Thanked 0 Times in 0 Posts
Array max length?
What is the longest possible array?
new Array(Number.MAX_VALUE) // ERROR.

01012006, 03:25 AM #2
 Join Date
 Oct 2005
 Location
 Arizona
 Posts
 336
 Thanks
 0
 Thanked 0 Times in 0 Posts
Originally Posted by DHTML Kitchen
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.

01012006, 09:19 PM #3
 Join Date
 Sep 2005
 Location
 Sydney, Australia
 Posts
 9,249
 Thanks
 4
 Thanked 932 Times in 919 Posts
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.

01012006, 09:22 PM #4
 Join Date
 Dec 2005
 Posts
 88
 Thanks
 0
 Thanked 0 Times in 0 Posts
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.

01032006, 04:51 PM #5
 Join Date
 Oct 2005
 Location
 Arizona
 Posts
 336
 Thanks
 0
 Thanked 0 Times in 0 Posts
"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)

01032006, 05:49 PM #6
 Join Date
 Dec 2005
 Posts
 88
 Thanks
 0
 Thanked 0 Times in 0 Posts
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.