swati-jagtap / javascript-practice

0 stars 0 forks source link

18.3.3--Read the countries api and count total number of languages in the world used as officials. #164

Open swati-jagtap opened 3 years ago

swati-jagtap commented 3 years ago
const fetch=require ("node-fetch")
const countriesAPI = 'https://restcountries.eu/rest/v2/all'
fetch(countriesAPI)
  .then(response=>response.json())
  .then(data=>{
     const uniqeLangArray=[];
     for(const l of data){
       const a=(l["languages"])
       for(let lObject of a){
         if(uniqeLangArray.indexOf(lObject["name"])==-1){
           uniqeLangArray.push(lObject["name"])
         }
         //console.log(lObject["name"])
       }

       //console.log(a[0])
     }
     console.log("total number of languages in the world used as officials:",uniqeLangArray.length)

  })

image