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

66
Views
Need to print countries using USD dollar in Restcountries API

I tried to print the countries using US Dollar in Restcountries API (https://restcountries.com/v3.1/all). I tried but nothing shows as an output:

My code as follows

const getUSDollar = () => {
  const xhr = new XMLHttpRequest();
  xhr.open("GET", "https://restcountries.com/v3.1/all", true);

  xhr.responseType = "json";

  xhr.onload = () => {

    const data = xhr.response;
    const datas = data.filter((value) => {
      for (var i in value.currencies.name.USD) {
        if (i === "Unites States Dollar") {
          return true;
        }
      }
    }).map((value) => value.name);
    console.log(datas);
  }
  xhr.send();
};

getUSDollar();

Please look into this.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Can you try this

  xhr.onload = () => {
    const data = xhr.response;
    const datas = data
      .filter((item) => item?.currencies?.USD?.name === "United States dollar")
      .map((value) => value.name);
    console.log('datas', datas);
  };

As @eglease suggested, you don't need to check the name, you can just check for USD and filter the obj like this,

  xhr.onload = () => {
    const data = xhr.response;
    const datas = data
      .filter((item) => item?.currencies?.USD)
      .map((value) => value.name);
    console.log('datas', datas);
  };

It worked for me. Try and comment whether this is what you are expected or not? enter image description here

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!