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

127
Vistas
JSON & API call is returning undefined

I'm trying to learn about basic API calls; I'm having issue with 'dialing in' to specific array objects in this Star Wars API.

I can console.log(json.people) or (json.planets), but cannot seem to go further than this, i.e. console.log(json.people.results) to show me an array of characters and associated data, as this shows as undefined...

I have attempted to parse / stringify the json, but am hitting a wall...

Would anybody be able to point me in the right direction?

Many thanks!

function getData() {

    url = "https://swapi.dev/api/?format=json";
    fetch(url).then((Response) => {
            return Response.json();
        })

        .then((json) => {
            console.log(json.people.results);
            console.log(json.planets);
        });      
}

getData();

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

0

This endpoint returns list of API's. So I take one of those and make another API call. You can skip the first step.

function getData() {

  var url = "https://swapi.dev/api/?format=json";
  fetch(url)
    .then((Response) => Response.json())
    .then((json) => {
      console.log(json)

      var url = json.people;
      fetch(url)
        .then((Response) => Response.json())
        .then((json) => {
          console.log(json)
        });

    });
}

getData();
.as-console-wrapper {
  max-height: 100% !important;
}

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