title: Create ArrayBuffer from Array (holding integers) and back again
body: <p>It seems so simple, but I cannot find out how to convert an <code>Array</code> filled with integers to an <code>ArrayBuffer</code> and back again to an <code>Array</code>. There are lots of examples where strings are converted to an <code>ArrayBuffer</code> like for example <strong><a href="https://developers.google.com/web/updates/2012/06/How-to-convert-ArrayBuffer-to-and-from-String?hl=en" rel="noreferrer">here</a></strong>.<br>
  Using these examples I created this:</p>
  
  <pre><code>/**
   * Convert string to array buffer.
   *
   * @param {Array.&lt;int&gt;} array
   * @returns {ArrayBuffer}
   */
  self.arrayToArrayBuffer = function( array ) {
      var length = array.length;
      var buffer = new ArrayBuffer( length * 2 );
      var view = new Uint16Array(buffer);
      for ( var i = 0; i &lt; length; i++) {
          view[i] = array[i];
      }
      return buffer;
  }
  </code></pre>
  
  <p>Then the array also needs to converted back again. For this I use:</p>
  
  <pre><code>var array = new Uint16Array(arrayBuffer);
  </code></pre>
  
  <p>This solution seems to work, but is there no easier way to do this?</p>
  
  <h2>UPDATE</h2>
  
  <p>It should also work for an array like:</p>
  
  <pre><code>var array = [3,7426,78921]
  </code></pre>