from a webserver I receive a large byte array that is composed of N integers (signed 16 bit, little endian) and I want to build an array of integers in javascript.
Of course I could just iterate over the incoming array and push in each couple of bytes. There’s no problem doing this.
I’m wondering if there is a more convenient way to fill the array. For example, in C, I may set an integer pointer to the first byte and then access to all the others. Or better I can malloc and memcpy the buffer area to a reserved space. In both cases I don’t have to iterate the source array.
In newer browsers that support Typed Arrays, you can make an XHR request with the
responseTyperequest parameter set to"arraybuffer". The response will then be anArrayBufferobject, which you can pass to aInt32Arrayconstructor.