You can use the set
method. Create a new typed array with all the sizes.
Example:
var arrayOne = new Uint8Array([2,4,8]);
var arrayTwo = new Uint8Array([16,32,64]);
var mergedArray = new Uint8Array(arrayOne.length + arrayTwo.length);
mergedArray.set(arrayOne);
mergedArray.set(arrayTwo, arrayOne.length);
Alternative: Convert your typed array in “normal” arrays. concat it and create a type array of it again.
In your case (solution):
let myArrays = [new Uint8Array(16384), new Uint8Array(16384), new Uint8Array(16384), new Uint8Array(16384), new Uint8Array(16384), new Uint8Array(8868)];
// Get the total length of all arrays.
let length = 0;
myArrays.forEach(item => {
length += item.length;
});
// Create a new array with total length and merge all source arrays.
let mergedArray = new Uint8Array(length);
let offset = 0;
myArrays.forEach(item => {
mergedArray.set(item, offset);
offset += item.length;
});
// Should print an array with length 90788 (5x 16384 + 8868 your source arrays)
console.log(mergedArray);