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

164
Vistas
for of loop return same item multiple times api double fetch

Console and browser display this In the first for of loop I get 10 different results as expected. in the second for loop when i call it it gives me 10 times the same result. why this happens and how do i fix it?

 const inputValue = document.getElementById("searchbarInput").value;
 const searchUrl = `https://stock-exchange-dot-full-stack-course-services.ew.r.appspot.com/api/v3/search?query=${inputValue}&limit=10&exchange=NASDAQ`;

const options = {
filter: '',
sort: 1}
async function displaydata() {
let url = searchUrl;
let response = await fetch(url);
let data = await response.json();

//log company info

const mappedList = data.map((x) => ({
    name: x.name,
    symbol: x.symbol,
    ceo: x.ceo
}))


for (let info of mappedList) {
    const companyInfo = await fetchMoreInfo(info.symbol);
    ceo = companyInfo.profile.ceo; // here returns a 10 different items
}

document.getElementById('root').replaceChildren();

for (comp of mappedList) {
    const div = document.createElement('div');
    div.innerHTML = `<a href="/company.html?symbol=${comp.symbol}">${ceo} ${comp.name}(${comp.symbol})</a>` + "<br>";
    document.getElementById('root').appendChild(div); //here it gives me the same  10 itmes}}

const fetchMoreInfo = async(companySymbol) => {
let url = `https://stock-exchange-dot-full-stack-course-services.ew.r.appspot.com/api/v3/company/profile/${companySymbol}`;
let response = await fetch(url);
let compData = await response.json();
return compData;

}

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