title: Print a JavaScript array to HTML, square brackets and quotation marks intact
body: <p>I'd like to set the attribute of an input form with an array of values (to use for autocomplete search). I have a JS array that looks a little something like this:</p>
  
  <pre><code>var suggestions = ["value1", "value2", "value3"];
  </code></pre>
  
  <p>Using jQuery, I did this:</p>
  
  <pre><code>$("#search-input").attr("data-source", suggestions);
  </code></pre>
  
  <p>Desired output:</p>
  
  <pre><code>&lt;input type='search' data-source='["value1", "value2", "value3"]' /&gt;
  </code></pre>
  
  <p>Actual output:</p>
  
  <pre><code>&lt;input type='search' data-source='value1, value2, value3' /&gt;
  </code></pre>
  
  <p>This breaks the autocomplete as it requires an array (or at least something that looks like a JavaScript array).</p>