I want to create a 64 bit array, whose limit is endless. But the 32 bit array limits to only 4,294,967,295 objects. I also get an error when I use the push function on an Array with the length 4,294,967,295 : Invalid array length
How can I create a 64 bit array?

- 451
- 5
- 15
-
Possible duplicate of [Maximum size of an Array in Javascript](https://stackoverflow.com/questions/6154989/maximum-size-of-an-array-in-javascript) – Oct 23 '18 at 13:25
2 Answers
According to ECMAScript definition this is the maximum length:
An integer index is a String-valued property key that is a canonical numeric String (see 7.1.16) and whose numeric value is either +0 or a positive integer ≤ 253−1. An array index is an integer index whose numeric value i is in the range +0 ≤ i < 232−1.
Handling two arrays could be a good idea.

- 228
- 2
- 11
-
The superscripts didn't copy correctly. You can format superscripts in questions using `` and `` – Oct 23 '18 at 13:22
-
@SimonCheng You're saying the *JavaScript specificiation* stating the maximum size of any array in JS doesn't answer your question? Really? – Oct 23 '18 at 13:31
-
-
-
-
-
But as @Amy said, its possible, but I don't see any possibility in creating more than 4294967296 objects – Binary Oct 23 '18 at 13:46
-
I didn't say it was possible. I said the complete opposite. JS array indexes are *only* 32-bit, even if you're using a 64-bit browser. – Oct 23 '18 at 13:47
-
Oh, OK then, so the final answer is there is no way, not a single method, to get past the limit, Thanks everyone for their contribution tho :) – Binary Oct 23 '18 at 15:44
-
Uh, no, the language spec explicitly states the maximum size of an array in JS. – Oct 23 '18 at 16:34
It's not possible as you already found out from @Amy and @sumitani. You can however implement your own object or "array container" or array wrapper as you wish.
I've put up a basic example here:
var MyArray = function(){
var arr1 = [];
var arr2 = [];
this.push = function(element){
if(arr1.length < 4294967296){
arr1.push(element);
}else if(arr2.length < 8589934592){
arr2.push(element);
}else{
throw "Invalid array length";
}
}
this.get = function(index){
if(index <= 4294967296){
return arr1[index];
}else if(index <= 8589934592){
return arr2[Math.floor(index / 4294967296)];
}else{
throw "Invalid Index";
}
}
Object.defineProperty(this, 'length', {get: function() {
return arr1.length + arr2.length;
}});
};
var arr = new MyArray();
for(var i = 0; i < 8589934592; i++){
arr.push(i);
}
console.log(arr.get(5));
console.log(arr.length);
So in theory it's possible to have an object to act as an array which is composed of multiple arrays and you just 'calculate' the right index for the right array.
I say in theory because this method will not work client-side as most browsers have their windows/tabs capped at specific MB/GB memory such as chrome and firefox.
The limit in Firefox is greater however and that's where I conducted my test.
The reason I'm giving this answer is because it makes no sense for OP to store such amount of data on the client (I only assume it's client-side) in the first place and it could be useful for hybrid applications (possibly).
This method can be easily expanded to utilise more space (and memory). There might be better ways of doing it, but that's my quick and dirty 2 cents.

- 8,271
- 2
- 26
- 43