我想合并多个数组缓冲区来创建一个 Blob。然而,如你所知, TypedArray没有“推送”或有用的方法...
例如:
var a = new Int8Array( [ 1, 2, 3 ] );
var b = new Int8Array( [ 4, 5, 6 ] );
因此,我想得到 [ 1, 2, 3, 4, 5, 6 ]
。
最佳答案
使用set
方法。但请注意,您现在需要两倍的内存!
var a = new Int8Array( [ 1, 2, 3 ] );
var b = new Int8Array( [ 4, 5, 6 ] );
var c = new Int8Array(a.length + b.length);
c.set(a);
c.set(b, a.length);
console.log(a);
console.log(b);
console.log(c);
关于javascript - 我如何在 JavaScript 中合并 TypedArrays?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14071463/