Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda