title: Convert ajax response array object to javascript array?
body: <p>I am using ajax to submit a login form in Yii. Here is my ajax function:</p>
  
  <pre><code>$("#login-form").submit(function() {
  
          var email = $("#email").val();
          var password = $("#password").val();
  
          $.ajax({
              url: "&lt;?php echo Yii::app()-&gt;request-&gt;baseUrl; ?&gt;/site/validatelogin",
              type: "post",
              data: "email=" + email + "&amp;password=" + password,
              success: function(response) {
                  if (response === "1") {
                      window.location.href = "&lt;?php echo Yii::app()-&gt;getBaseUrl(true); ?&gt;/dashboard";
                  }
                  else
                  {
                      //Dispaly response errors above login form
                  }
              },
              error: function() {
                  alert("Could not perform the requested operation due to some error.");
                  return false;
  
              }
          });
  
      });
  </code></pre>
  
  <p>My PHP controller function is validatelogin as follows:</p>
  
  <pre><code> $email = $_POST['email'];
      $password = $_POST['password'];
  
  
      $model = new LoginForm();
  
      $model-&gt;email = $email;
      $model-&gt;password = $password;
  
  
      if ($model-&gt;validate() &amp;&amp; $model-&gt;login()) {
          echo "1";
      } else {
          print_r($model-&gt;getErrors());
      }
  </code></pre>
  
  <p>If the user enters correct credentials I send 1 as response to view and user is redirected to dashboard.</p>
  
  <p>But if user enters incorrect credentials then different errors are received in ajax response depending upon the type of error. </p>
  
  <p>I want to display those errors above login form in else part of success function through a loop. </p>
  
  <p>But when I run the loop over response then that array has very large length i.e for example if the error in response was "Incorrect password" then the response array has length of 18(the number of characters) in the error message. In short the response array is like:</p>
  
  <pre><code>array('I','n','c','o','r','r'....)
  </code></pre>
  
  <p>rather than</p>
  
  <pre><code>array([0]=&gt;"Incorrect password")
  </code></pre>
  
  <p>How do I convert response array in the latter format and iterate over each index to display error message to the user above the login form?</p>