Converts a string or byte array to a byte array using UTF-8 encoding. If the input is already a byte array, it is returned as-is.
The string or byte array to convert.
The input as a byte array.
stringToBytes('Hello') // Returns Uint8Array([72, 101, 108, 108, 111]) Copy
stringToBytes('Hello') // Returns Uint8Array([72, 101, 108, 108, 111])
Converts a string or byte array to a byte array using UTF-8 encoding. If the input is already a byte array, it is returned as-is.