Uint8Array 声明
let u8a=new Uint8Array(10);
console.log(u8a);//Uint8Array(10) [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
console.log(u8a.buffer);//ArrayBuffer{} .bytelength 为10
u8a.set([15,16,17],0)
console.log(u8a);//Uint8Array(10) [15, 16, 17, 0, 0, 0, 0, 0, 0, 0]
比如说,我们想将其中的16,17,0,0拿出来组成一个新的uint8array,那有什么简单的办法,首先看官方api
uint8array 有一个方法
subarray 方法 (Uint8Array)
为此数组获取 ArrayBuffer 存储的新 Uint8Array 视图。
看下面代码