How to convert between string type and BYTE array in Mini Program JS code?

* * for example: how to convert the string "123456" to the BYTE array Uint8Array [0x01,0x02,0x03,0x04,0x05, 0x06]
and vice versa, how to convert this array to the string "123456"? * *

Mar.22,2022

function Uint8ToStr(arr){
  for (var i = 0,str=''; i < arr.length; iPP) 
    str+= String.fromCharCode(arr[i]);
  return str;
}

function strToUint8(str){
  for (var i = 0,arr=[]; i < str.length;iPP){
    arr.push(str.charCodeAt(i));
  }
  return new Uint8Array(arr);
}
Menu