How to store a byte array in Javascript
By using typed arrays, you can store arrays of these types:
- Int8
- Uint8
- Int16
- Uint16
- Int32
- Uint32
- Float32
- Float64
For example:
var array = new Uint8Array(100);array[42] = 10;alert(array[42]);
See it in action here.
var array = new Uint8Array(100); array[10] = 256;array[10] === 0 // true
I verified in firefox and chrome, its really an array of bytes :
var array = new Uint8Array(1024*1024*50); // allocates 50MBytes
You could store the data in an array of strings of some large fixed size. It should be efficient to access any particular character in that array of strings, and to treat that character as a byte.
It would be interesting to see the operations you want to support, perhaps expressed as an interface, to make the question more concrete.