How can I merge TypedArrays in JavaScript?

后端 未结 7 490
说谎
说谎 2020-12-09 01:01

I\'d like to merge multiple arraybuffers to create a Blob. however, as you know, TypedArray dosen\'t have \"push\" or useful methods...

E.g.:

var a          


        
7条回答
  •  醉酒成梦
    2020-12-09 01:38

    As a one-liner, which will take an arbitrary number of arrays (myArrays here) and of mixed types so long as the result type takes them all (Int8Array here):

    let combined = Int8Array.from(Array.prototype.concat(...myArrays.map(a => Array.from(a))));
    

提交回复
热议问题