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

143
Views
How find empty array and object , in object

I have an object that has data (null) and other objects with an array whose values ​​are also null, if all values ​​are null then false, if at least one is something else then true. How do I parse this object and see if all the data is null and get true/false

Object { employerCompanyName: null, companyBenefitsProviderName: null, companyRepresentative: null, website: null, logonID: null, password: null, benefitsDetails: (1) […], coverageDetails: (1) […], beneficiaryDetails: (1) […], notes: null }

​ beneficiaryDetails: Array [ {…} ] ​​ 0: Object { beneficiary: null, allocation: null } ​​ length: 1 ​​ : Array [] ​ benefitsDetails: Array [ {…} ] ​​ 0: Object { benefitsPackageType: null, benefitsCoverageDetails: [], policyNumber: null } ​​ length: 1 ​​ : Array [] ​ companyBenefitsProviderName: null ​ companyRepresentative: null ​ coverageDetails: Array [ {…} ] ​​ 0: Object { familyMemberCovered: null, currency: null, amount: null } ​​ length: 1 ​​ : Array [] ​ employerCompanyName: null ​ logonID: null ​ notes: null ​ password: null ​ website: null

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Created the test objects to spec. Defined logic for setting flag and logging values when something other than null exists either inside object or within an array in that object.

Pass object to Object.entries for testing. Simply wrap this logic in a function that passes the parameter along into Object.entries and return out whatever is required.

let thing1 = {a: null, b: [null, null, null]};
let thing2 = {a: null, b: [null, null, 'value']};
let thing3 = {a: 'something', b:[null, null, null]};

let flag = false;
for( [key,val] of Object.entries(thing1) ){
  if(val && !Array.isArray(val)){
    console.log(val);
    flag = true;
  } else if(Array.isArray(val)){
    for(let i = 0; i < val.length; i++){
      if(val[i] !== null){
        console.log( val[i] );
        flag = true;
      }
    }
  }
}

Remains false for thing1, flag set to true and logs value for thing2 and thing3.

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!