Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

105
Vistas
API request with Svelte returning object in DOM

I'm struggling to understand why my loop is displaying this:

[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]
[object Object]

I tried many things with fetch and axios but it ends the same way 😞

Here is my Svelte component:

<script>
  import axios from 'axios';

  let results = [];

 const fetchYoutubeList = async () => {
    const searchQuery = 'mySearch';
    const maxResults = 10;
    const apiKey = import.meta.env.VITE_APP_YOUTUBE_API_KEY;
    const apiBaseUrl = import.meta.env.VITE_APP_API_BASE_URL;

    await axios.get(`${apiBaseUrl}`, {
      params: {
        part: 'snippet',
        maxResults: maxResults,
        q: searchQuery,
        type: 'video',
        key: apiKey
      }
    })
      .then(response => {
        console.log(response.data);
        results = response.data.items;
        console.log(results);
        console.log(typeof results);
      });
  };
</script>

<section>
  <button
    class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded mt-2"
    on:click|once={fetchYoutubeList}
  >
    Bring me joy
  </button>

  <div>
    <ul>
      {#each results as item }
        <li>
          {item.id}
        </li>
      {/each}
    </ul>
  </div>
</section>

Here the results of my logs: console logs

I think I missed something but I can't find what, so if some of you have an idea I would be glad if you can debug me 😊

Thanks 🙏

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

[UPDATE]- Solution

Thanks to @pilchard, I found my mistake here.

I was trying to loop through an object because my item.id was an object (weird by the way ^^), so everything is ok I manage to do my loop normally. 🔁

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda