const str = "abc";
let unicodeArray: Number[] = [];
let code = 0;
for (let i = 0; i < str.length; ++i) {
code = str.charCodeAt(i);//returns number
unicodeArray = unicodeArray.concat([code]);
}
//unicodeArray: [97, 98, 99];
let byteArray = new Uint8Array(unicodeArray);
new Uint8Array() gives the following error message:
No overload matches this call. The last overload gave the following error. Argument of type 'Number[]' is not assignable to parameter of type 'ArrayBufferLike'. Type 'Number[]' is missing the following properties from type 'SharedArrayBuffer': byteLength, [Symbol.species], [Symbol.toStringTag]
See Uint8Array reference at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array var arr = new Uint8Array([21,31]);
May I know what is wrong?