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

174
Views
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 answers
Answer question

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 Report
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!