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

177
Visualizações
How would I specify that I just want to request the top 5 elements in the coin.rank array and not the top 50?

I am trying to figure out how I would just request the top 5 crypto coins via api request to coinranker as I want them to fit on a section on my html page. As of now I am requesting the entire index.

fetch(`${proxyUrl}${baseUrl}`, { 
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'X-My-Custom-Header': `${apiKey}`,
      'Access-Control-Allow-Origin': "*"
    }
})
  .then((response) => {
    if (response.ok) {
      response.json().then((json) => {
        console.log(json.data);
        let coinsData = json.data.coins;

        if (coinsData.length > 0) {
          var cryptoCoin = "";
        }
        coinsData.forEach((coin) => {
          cryptoCoin += "<tr>";
          cryptoCoin += `<td> ${coin.rank}</td>`;
            
          cryptoCoin += `<td> ${coin.btcPrice} </td>`;
          
          cryptoCoin += `<td> ${coin.name}</td>`;
          cryptoCoin += `<td> $${Math.round(coin.price*100)/100}</td>`;
          cryptoCoin += `<td> ${coin.symbol}</td>`;"<tr>";
        });
        document.getElementById("data").innerHTML = cryptoCoin;
      });
    }
  })
  .catch((error) => {
    console.log(error);
});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For your API in particular (Coinranker API), it looks like you can provide a limit attribute as a query parameter in your request like so:

fetch(`${proxyUrl}${baseUrl}?limit=5`, { 
    method: 'GET',
    headers: {
      'Content-Type': 'application/json',
      'X-My-Custom-Header': `${apiKey}`,
      'Access-Control-Allow-Origin': "*"
    }
})

Otherwise, you can use manually get the first 5 results by setting it's length, and slicing it:

coinsData.length = Object.keys(coinsData).length;
coinsData = Array.prototype.slice.call(coinsData, 5));
about 4 years ago · Juan Pablo Isaza Relatório
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