title: MVC: Iterating a Viewbag array in javascript
body: <p>The goal is to get the data from the <code>ViewBag.Array</code> to a Javascript array. The data is calculated in the controller so I cannot fetch it straight from the database. I need the data to draw a chart with jqplot. Code:</p>
  
  <pre><code>for(i = 0; i &lt; @ViewBag.Array.Length; i++)
  {
      jScriptArray[i] = @ViewBag.Array[i];
  }
  </code></pre>
  
  <p>The problem is "'i' does not exist in the current context" in the <code>@ViewBag.Array[i]</code> but has no problems in the <code>jScriptArray[i]</code>. Any help is appreciated.</p>