title: Pass array from Controller to Ajax
body: <p>I have a Symfony project where I make an AJAX call.</p>
  
  <p><strong>Controller.php</strong></p>
  
  <pre class="lang-php prettyprint-override"><code>/**
       * @Route("/juegoAuto", options={"expose"=true}, name="juegoAuto")
       */
      public function juegoAuto(Request $request)
      {
          if ($request-&gt;isXmlHttpRequest()) {
              $em = $this-&gt;getDoctrine()-&gt;getManager();
  
              (...)
  
              $idPartida = $jugador-&gt;getPartida();
              $jugadores = $em-&gt;getRepository(Jugador::class)-&gt;findBy(['partida' =&gt; $idPartida]);
  
              return new JsonResponse(['id' =&gt; $id, 'jugadores' =&gt; $jugadores]);
          } else {
              throw new \RuntimeException('Y te pillé');
          }
      }
  </code></pre>
  
  <p>The parameter 'id' shows me well, the problem is with the array of 'jugadores' that I receive in the .js file and by console it prints this to me:</p>
  
  <p><code>functions.js:212 Object</code></p>
  
  <p><code>functions.js:213 clicod: [object Object] - Indice: 0</code></p>
  
  <p><code>functions.js:212 Object</code></p>
  
  <p><code>functions.js:213 clicod: [object Object] - Indice: 1</code></p>
  
  <p>I have tried it in many ways:</p>
  
  <pre><code>$.each(data['jugadores'], function(indice, valor) {
      console.dir(valor);
      console.log('clicod: ' + valor + ' - Indice: ' + indice);
  })
  </code></pre>
  
  <p><code>console.log(JSON.parse(JSON.stringify(data['jugadores'])))</code></p>
  
  <p><code>console.log(data['jugadores'].toString())</code></p>
  
  <p>And there is no way. If anyone could help me ... thanks. The problem is that it says that they are Objects but I enter them and they are empty. On the other hand, if I make the same request and print it in twig, it does return data.</p>
  
  <p><a href="https://i.stack.imgur.com/Mhzi6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mhzi6.png" alt="image of what the console returns"></a></p>