xxxxxxxxxx
// new js standard is to use a TextEncoder
let utf8 = new TextEncoder();
let bytes = utf8.encode("myString")
//
xxxxxxxxxx
function strToUtf16Bytes(str) {
const bytes = [];
for (ii = 0; ii < str.length; ii++) {
const code = str.charCodeAt(ii); // x00-xFFFF
bytes.push(code & 255, code >> 8); // low, high
}
return bytes;
}