Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
How to filter the following list using Lodash `_.filter()`

I have the following list named cart:

cart = [ {"state": "Canada", "id": "1"}, {"state": "USA", "id": "1"} ]
       

I have tried filtering it according to the following code where state should either be (USA, Canada), but its giving errors:

var oddNo = _.filter(cart, {'state': {"Canada", "USA"}, 'id': "1"});
console.log(oddNo);

What would be the correct way of doing it?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

i'm guessing this is loadash or underscore? the easiest way will be to pass a function as the second parameter that filters the array. _.filter(cart, (items) => {return item.state === 'USA' || item.state ==='Canada'}) check out the docs on lodash https://lodash.com/docs/4.17.15#filter

although really you probably dont need lodash for this and can just use native js filter https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda