Convert String to bytes

How to Convert String to Bytes in pre-script?

var string = โ€œTestโ€;

trying to achieve similar like below:

bytes by = string.getBytes();

I tried with below code but not able to successful :

function getBytes(str) {
for (var bytes = , i = 0; i < str.length; i++)
bytes.push(str.charCodeAt(i) & 0xFF);
return bytes;
}

Any help would be greatly appreciated.

1 Like