Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

144
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda