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

193
Views
How to filter array on basis of multiple value?

I am using Javascript filter function for filtering the array. Array containing the objects related to Covid cases. I am using Rapid API for fetching the world covid cases details.

import axios from 'axios'

export const stats_API = async (setWorldStats, setcasesAcrossWorld) => {
  try {
    const url = `https://covid-193.p.rapidapi.com/statistics`

    const headers = {
      'x-rapidapi-host': 'covid-193.p.rapidapi.com',
      'x-rapidapi-key': '******************',
    }
    const { data } = await axios.get(url, { headers })

    let casesAcrossWorld_Arr = data.response.filter((val) => {
      return val.country === 'All'
    })

    setcasesAcrossWorld(casesAcrossWorld_Arr[0])

Filtering worldStats_Arr on the basis of All & ASIA

    let worldStats_Arr = data.response.filter((val) => {
      return val.country !== 'All' && val.country !== 'Asia'
    })

Now second time again but with different conditions on Filtering worldStats_Arr on the basis of EUROPE & AFRICA

    worldStats_Arr = worldStats_Arr.filter((val) => {
      return val.country !== 'Europe' && val.country !== 'Africa'
    })

Now again filtering & so on...


    worldStats_Arr = worldStats_Arr.filter((val) => {
      return val.country !== 'North-America' && val.country !== 'South-America'
    })

    worldStats_Arr = worldStats_Arr.filter((val) => {
      return val.country !== 'Oceania' && val.country !== 'Africa'
    })

    setWorldStats(worldStats_Arr)
  } catch (error) {
    console.log(error)
  }
}

As you will see I am filtering worldStats_Arr again again so that I can fullfill multiple filters condition.

Is there any other way or a good practice? How can I filter array on the basis of multiple filtering scenarios.

about 4 years ago · Juan Pablo Isaza
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!