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

138
Visualizações
How in Javascript to esxclude from an Array of Objects the items which contain specific pair of keys and values

I created this snippet to understand the issue

JSFiddle

I'm trying with a filter to exclude from an array all the items which have 2 specific keys as value === 'True' and team === 'Avengers'.

characters.filter(character => character.team !== 'Avengers' && character.value !== 'True');

My goal is to see as a result the following Object

[{
  name: "Flash",
  team: "Justice League",
  value: "False"
}, {
  name: "Deadpool",
  team: "X-Force",
  value: "False"
}]

As you see I should not see any item which has value === 'True' and also all the items which have team === 'Avengers'

But from the fiddles, you see that I'm having a wrong result and I don't know how to fix this as there are 2 items that should be excluded because they have value === true but are not as you see below

[{
  name: "Flash",
  team: "Justice League",
  value: "False"
}, {
  name: "Deadpool",
  team: "X-Force",
  value: "False"
}, {
  name: "Deadpool",
  team: "X-Force",
  value: "true"
}, {
  name: "Deadpool",
  team: "X-Force",
  value: "true"
}]
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

String comparison is case-sensitive: a string that equals 'True' is not a string that equals 'true'.

You can fix this by including both in your filter condition:

character.team !== 'Avengers' && character.value !== 'True' && character.value !== 'true'

or (what I would probably do since it’s more durable) convert the string to upper-case before comparing for a case-insensitive comparison:

character.team.toUpperCase() !== 'AVENGERS' && character.value.toUpperCase() !== 'TRUE'

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