title: Print hex or decimal values of byte array in JavaScript
body: <p>I have a function in JavaScript which is expecting a byte array to be passed into it from Native C++ code. For example:</p>
  
  <pre><code>function OnEvent(event, data1)
  {
       console.log("data1[0] = " + data1[0]);
  }
  </code></pre>
  
  <p>I would like for it to print 0x55 or even the decimal value of it. For some reason, I am seeing the following in the console log:</p>
  
  <p><img src="https://i.stack.imgur.com/WrtXP.jpg" alt="enter image description here"></p>
  
  <p>How can I print the hex value of the byte or even the decimal value without printing the character?</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I went to the link below thanks to Vinothbabu. I used the unpack function:</p>
  
  <pre><code>function unpack(str) { 
      var bytes = []; 
      $("#homePage").append("str.length = " + str.length + "&lt;br&gt;"); 
  
      for(var i = 0, n = str.length; i &lt; n; i++) { 
          var char = str.charCodeAt(i); 
          $("#homePage").append("char is equal to " + char + "&lt;br&gt;"); 
          bytes.push(char &gt;&gt;&gt; 8, char &amp; 0xFF); 
      }
  
      return bytes; 
  }
  </code></pre>
  
  <p>It prints "char is equal to 65533" and the value of "bytes" prints out "255, 253" which means it has a value of 0xFFFD.</p>
  
  <p>This is not the data/payload that I was expecting. Do you know why there are 2 bytes?</p>