Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
¡Hola a todos! Necesito mostrar en pantalla el PRIMER objeto de la API: http://dummy.restapiexample.com/api/v1/employees
<body> <h1>This is a page</h1> <div id="page"></div> <script> fetch("http://dummy.restapiexample.com/api/v1/employees") .then(response => response.json()) .then(data => { console.log(data) document.querySelector("#page").innerText = JSON.stringify(data) }) </script>

aquí está mi intento, que muestra todos los objetos, pero solo necesito el primero

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Dado que la API devuelve un objeto con atributos de success y data , consideraré que desea el primer objeto data para el primer empleado.

Mire Trabajar con objetos en la documentación, es un conocimiento imprescindible en Javascript.

 <body> <h1>This is a page</h1> <div id="page"></div> <script> fetch('http://dummy.restapiexample.com/api/v1/employees') .then(response => response.json()) .then(data => { document.body.innerText = JSON.stringify(data.data[0]); }); </script> </body>

about 4 years ago · Juan Pablo Isaza Report

0

<body> <h1>This is a page</h1> <div id="page"></div> <script> fetch("http://dummy.restapiexample.com/api/v1/employees") .then(response => response.json()) .then(data => { console.log(data[0]) //notice the index in data document.querySelector("#page").innerText =JSON.stringify(data[0]) }) </script>

Eso supondría que los datos son una matriz de objetos, podría seleccionar el primer elemento como lo haría en cualquier matriz. Sin ver la estructura de respuesta, ese sería el enfoque lógico.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!