title: Pass C# Array To Javascript
body: <p>What is the best way to pass C# array to javascript variable ?</p>
  
  <p>I have sample code but this return character by character from C# array, I want to return in normal way like word by word in javascript array;</p>
  
  <p>C# code behind:</p>
  
  <pre><code> public string[] names = { "John", "Pesho", "Maria"};
   public JavaScriptSerializer javaSerial = new JavaScriptSerializer();
  </code></pre>
  
  <p>javascript code:</p>
  
  <pre><code> &lt;script&gt;
      var a = '&lt;%= this.javaSerial.Serialize(this.names) %&gt;';
      for (var i = 0; i &lt; a.length; i++) {
          console.log(a[i]);
      }
   &lt;/script&gt;
  </code></pre>
  
  <p>This script return all words from "names" array in single char array . I want to return in normal way like ["John"] ["Pesho"] ... </p>
  
  <p><b>What is the best way to pass C# array to javascript ? </b></p>
  
  <p>When I run this code I get the following in console of Chrome browser:</p>
  
  <pre><code>[ Profile.aspx:44
  " Profile.aspx:44
  v Profile.aspx:44
  a Profile.aspx:44
  l Profile.aspx:44
  e Profile.aspx:44
  r Profile.aspx:44
  i Profile.aspx:44
  " Profile.aspx:44
  , Profile.aspx:44
  " Profile.aspx:44
  p Profile.aspx:44
  e Profile.aspx:44
  s Profile.aspx:44
  h Profile.aspx:44
  o Profile.aspx:44
  " Profile.aspx:44
  , Profile.aspx:44
  " Profile.aspx:44
  m Profile.aspx:44
  a Profile.aspx:44
  r Profile.aspx:44
  i Profile.aspx:44
  a Profile.aspx:44
  " Profile.aspx:44
  ] 
  </code></pre>