title: Javascript ascii string to hex byte array
body: <p>I am trying to convert an ASCII string into a byte array.</p>
  
  <p>Problem is my code is converting from ASCII to a string array and not a Byte array:</p>
  
  <pre><code>var tx = '[86400:?]';
  for (a = 0; a &lt; tx.length; a = a + 1) {
      hex.push('0x'+tx.charCodeAt(a).toString(16));
  }
  </code></pre>
  
  <p>This results in:</p>
  
  <pre><code> [ '0x5b','0x38','0x36','0x30','0x30','0x30','0x3a','0x3f','0x5d' ]
  </code></pre>
  
  <p>But what I am looking for is:</p>
  
  <pre><code>[0x5b,0x38 ,0x30 ,0x30 ,0x30 ,0x30 ,0x3a ,0x3f,0x5d]
  </code></pre>
  
  <p>How can I convert to a byte rather than a byte string ?</p>
  
  <p>This array is being streamed to a USB device:</p>
  
  <pre><code>device.write([0x5b,0x38 ,0x30 ,0x30 ,0x30 ,0x30 ,0x3a ,0x3f,0x5d])
  </code></pre>
  
  <p>And it has to be sent as one array and not looping sending device.write() for each value in the array.</p>