Home >Web Front-end >Front-end Q&A >How big can a JavaScript array be?
JavaScript arrays can have up to 4294967295 elements; according to the "ECMA-262" 5th edition specification, the maximum length of the array is bound by an unsigned 32-bit integer, so the longest array can have "2 32nd power -1", which is 4294967295 elements.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The maximum length of an array is Math.pow(2,32)-1, 2 to the 32nd power-1.
Manual To test it, a simple loop is definitely unrealistic, so we decided to directly define the length of the array for testing.
Obviously, this array does not exceed the maximum length, so length can be output normally.
And when we change this value into Math.pow(2.32)
, the output is an invalid array length. From this, it can be seen that the maximum length of the js array It is indeed 2 to the 32nd power - 1;
According to the ECMA-262 5th edition specification, the maximum length of the array is bound by an unsigned 32-bit integer. The reason is the ToUint 32 abstract operation, so the longest The array can have 2.32-1=4 294 967 295=4.29 billion elements.
Related recommendations: javascript learning tutorial
The above is the detailed content of How big can a JavaScript array be?. For more information, please follow other related articles on the PHP Chinese website!