Based on the answer here, you can roughly calculate the size of different data-types in JavaScript.
The equations used, pertaining directly to your question, to calculate the size in bytes:
string = string.length * 2
number = 8
Based on this, the size of your array
variable would depend on the content-type being placed in it. As you're inserting numeric values, each offset would be 8 bytes, so:
array[number] = array.length * 8
With these equations, the sizes are:
string = 20000
array = 80000
If you were to use array.push('0')
instead (i.e. use strings), the sizes of string
and array
should be roughly equal.
References:
The String Type - EMCAScript Language Specification:
The String type is the set of all finite ordered sequences of zero or more 16-bit unsigned integer values.
The Number Type - EMCAScript Language Specification:
The Number type has exactly 18437736874454810627 (that is, 264−253+3) values, representing the double-precision 64-bit format IEEE 754 values as specified in the IEEE Standard for Binary Floating-Point Arithmetic