Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!