xxxxxxxxxx
// Function to convert text to ArrayBuffer
function textToArrayBuffer(text) {
const encoder = new TextEncoder();
return encoder.encode(text).buffer;
}
// Usage example
const myText = "Hello, world!";
const myArrayBuffer = textToArrayBuffer(myText);
// Logging the ArrayBuffer
console.log(myArrayBuffer);