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

118
Views
how to add an array to my HTML body with a API

I would like to know how I can make an API arrangement appear directly in my HTML body, because when I try to do it it returns [object, object]

This is the array in console:

code: "IT" confirmed: 12134286, country: "Italy" , critical: 343 , deaths: 754169

This is my code:

const body = document.querySelector('body')
const button = document.querySelector('.button')

const result = () => {
  fetch("https://covid-19-data.p.rapidapi.com/country/code? 
  code=it", {
  "method": "GET",
  "headers": {
     "x-rapidapi-host": "covid-19-data.p.rapidapi.com",
      "x-rapidapi-key": "596ab7b883msh9846bfe9508ejsn1508f3534ee0"
  }
})
       .then(response => response.json())
       .then(data => {
         data.forEach(result => {
          console.log(result)
          const h2 = document.createElement('h2')
          h2.innerHTML = result
          body.appendChild(h2)
        })

     .catch(err => {
       console.error(err);
     });
    }

 button.addEventListener('click', () =>{
  result();
})
about 4 years ago · Santiago Gelvez
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!