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

137
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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