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

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

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