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

108
Vistas
Call API have duplicate Data and output 500 arry

i need some help in my code

if see the visit api url you will see Large Data duplicated

const url = 'https://raw.githubusercontent.com/globaldothealth/monkeypox/main/latest.json';



async function getData() {
    const response = await fetch(url);
    const data = await response.json();
    console.log(data);

How we Can Merge all data and Sum it like to show have 500 infected named Confirmed And SUSPACKTED AND SHOW IT BY Numbar

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

0

You simply need an object to store and count the cases while iterating over the array of persons. Find an implementation below:

const url =
  "https://raw.githubusercontent.com/globaldothealth/monkeypox/main/latest.json";

async function getData() {
  const response = await fetch(url);
  const data = await response.json();
  return data;
}

function getResults(data) {
  const results = {
    confirmed: 0,
    suspected: 0,
  };
  data.forEach((person) => {
    switch (person.Status) {
      case "confirmed":
        results.confirmed ++;
        break;
      case "suspected":
        results.suspected ++;
        break;
      default:
        break;
    }
  });
  return results;
}

(async function () {
  const data = await getData();
  const results = getResults(data);
  console.log(
    `${results.confirmed} confirmed cases\n${results.suspected} suspected cases.`
  );
})();

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