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

270
Views
Hi, everyone! I need to show on the screen FIRST object of the 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>

here is my try, which shows all objects, but I need only the first one

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

0

Since the API returns an object with success and data attributes, I'll consider you want the first data object so the first employee.

Look at Working with objects on documentation, it's must-have knowledge in 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>

That would be assuming the data is an array of objects, you could pick up the first element as you would in any array. Without seeing the response structure that would be the logical approach.

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!