title: javascript: How do I convert Uint8Array data to a JS object
body: <p>I am new to both Javascript and JSON worlds. I am wondering how I could convert an incoming Uint8Array data () to a JS object?
  Any help / pointers please. Here's what I have done as an experiment.</p>
  
  <pre><code>// arr is uint8Array incoming data
  function myConvertFunc(arr) {
    let str = "";
    for (var i=0; i&lt;arr.byteLength; i++) {
      str += String.fromCharCode(arr[i]);
    }
  
    // Say, 'str' at this step looks like below :
    /* {"type": "newEvent", "content": {"rec": [{"id1": "1", "event": "3A=","payload": "EZm9ydW0ub="}]}} */
  
    var serializedData = JSON.stringify(str);
    let message = JSON.parse(serializedData);
  
    switch (message.type) {
      case "newEvent":
        log("In newEvent");
        break;
       .
       .
       .
      default:
        log("undefined message type");
    }
  }
  </code></pre>
  
  <p>Contrary to my understanding, the default case log : <strong>"undefined message type"</strong> is show in my logs. Could someone please help me figure out my mistake here?</p>