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

126
Vistas
Need to check if any one of two keys are there in object javascript

I am trying to check if any one of the two given keys are available in a given object

let keys = ['foo', 'bar'];

given object

let obj = {
  "foo": "value"
}

let obj1 = {
  "key": "value"
}

As we can see in obj foo is present and in obj1 none of the given keys are present.

"key" in obj //can check for single key like this

Need to check anyone of given key should be present in object

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use Object.keys combined with Array.prototype.includes:

let obj = {
  foo: 'value',
  key: 'value'
}

let keys = ['foo', 'bar']

// true
console.log(Object.keys(obj).some(k => keys.includes(k)));

keys = ['bar','bar'];
// false
console.log(Object.keys(obj).some(k => keys.includes(k)));

about 4 years ago · Juan Pablo Isaza Denunciar

0

Use Array#some to iterate over the keys list and Object#hasOwnProperty to check if the object has a key:

const hasKeyInList = (obj = {}, keys = []) =>
  keys.some(key => obj.hasOwnProperty(key));

const keys = ['foo', 'bar'];
console.log( hasKeyInList({"foo": "value"}, keys) );
console.log( hasKeyInList({"key": "value"}, keys) );

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