Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda