Is there a better way to output a javascript array from ASP.net? I often run into the problem of producing a javascript array on an ASP.net page from an IEnumerable and I was wondering if there was an easier or clearer way to do it than

&lt;% bool firstItem = true;
   foreach(var item in items){
      if(firstItem)
      {
         firstItem = false;
      }
      else
      {%&gt;
        ,
      &lt;%}%&gt;
     '&lt;%:item%&gt;'
  %&gt;


The whole thing is made much more verbose because of IE's inability to handle a hanging comma in an array or object.
With a bit of help from System.Linq this becomes quite easy.

var array = [ &lt;%= 
    string.Join(",", items.Select(v =&gt; "'" + v.ToString() + "'").ToArray())  
%&gt; ];