title: is it possible to store javascript array in json?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2295496/convert-javascript-array-to-json">Convert Javascript Array to JSON</a>  </p>
  </blockquote>
  
  
  
  <p>I am trying to figure out how to return an array and store it in json variable as string, is that possible? [If not, how can I return all the outputs and store it json?] - If you know what I mean...</p>
  
  <pre><code>    //arr = ["a", "b", "c", "d", "ddd"]
      //largest = 3
      var generateEntryCodes = function(arr, largest) {
          var newText = ""
          for(var i=0; i &lt; arr.length; i++) {
              if (arr[i] == null) {
                  arr.splice(i, 1);
                  i--;
              }
              var counts = arr[i].length != largest ? (parseInt(largest) - parseInt(arr[i].length)) : 0
              for (var z=0; z&lt;counts;z++)
                  newText += "0"
              var result = arr[i].splice( 0, 0, newText )
              newText = ""
              result = [{
                  "result": result, 
                  "total": result.length
              }]
          }
          return result
      }
  </code></pre>
  
  <p>I am try to output the above code as:</p>
  
  <pre><code>00a
  00b
  00c
  00d
  ddd
  </code></pre>
  
  <p>But as I flash the result json. I only get "ddd"... So I tried adding before the <strong>result = [{}]</strong> jSON code:</p>
  
  <pre><code>$("textarea").val( $("textarea").val("") + result + "\n")
  //outputs:
     00a
     00b
     00c
     00d
     ddd
  </code></pre>
  
  <p>How can I get all the outputs from <strong>result</strong> variable and store it in <strong>JSON</strong> variable.</p>
  
  <p><strong>Problem: Code only store into JSON the last array.</strong></p>