How do I translate this Python to Javascript? BYTE_ARRAY = bytearray(b"x01")

Question:

I need to turn this line of Python to Javascript

BYTE_ARRAY = bytearray(b"x01")

Asked By: Miguel

||

Answers:

Uint8Array is like the bytearray Python function. It is used to create a byte array from hexadecimal.

const BYTE_ARRAY = new Uint8Array([0x01]);

Docs: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array

Answered By: iohans
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.