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

234
Vistas
How to gain access to if statement checked value ? in side the if block?

How to gain access to if statement checked value (case), inside the if block after the check happend ? instead of having to write another 4 conditional according to each case ?

if ((obj.a === '' || obj.b === '' || obj.c === '' || obj.d === '')) {
      console.log(what case has been triggered ?)
      selected.a ? something : null
      selected.b ? something : null
      selected.c ? something : null
      selected.d ? something : null
    }

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

0

You can create an object that contains the result of each of a comparisons in a object with the corresponding keys using Array.reduce:

const obj = { a: " ", b: " ", c: " ", d: " " };

const boolObj = Object.keys(obj).reduce((accum, key) => {
    accum[key] = obj[key] === " ";
    return accum;
}, {}); // result: {a: true, b: true, c: true, d: true}

Then, you can check for validity using Array.every:

if (Object.values(boolObj).every(val => val)) {
    // do something
}

However, since you did not provide some better context, I cannot give a better answer that fits your needs. To me, I think this is over-engineering, and I'm quite sure there probably are much better ways of solving the problem relative to your context.

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