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

208
Vistas
using fake API from jsonpalceholder, how to append the returned data from api to a list - javascript

I am using API with javascript for first time, so I am using jsonplaceholder fake API.

I have an array of objects and I am trying to iterate over a property in this array of object but I got this error:

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'appendChild')

Here is my code

const api_url = 'https://jsonplaceholder.typicode.com/users';
let specialisty = document.getElementById('specialisty-menu');
async function getUser() {
  // Making an API call (request)
  // and getting the response back
  const response = await fetch(api_url);

  // Parsing it to JSON format
  const data = await response.json();
  console.log(data);

  let name = data.map((a) => a.name);
  console.log(name);
  for (let i = 0; i < name.length; i++) {
    console.log(name[i]);
    let item = document.createElement('a');
    item.appendChild(document.createTextNode(name[i]));
    specialisty.appendChild(item);
  }
}

getUser();
<div id="specialisty-menu"></div>

about 4 years ago · Juan Pablo Isaza
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