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

213
Visualizações
Scenario based check on undefined value in fields in array of objects javascript

I have a scenario to check the undefined and empty string in object array in javscript. Below code is partially working, got stuck.

In the array object,

if field value is undefined or empty return true only when newemp is false

If field value except country other fields are undefined or empty return true only when newemp is true

Else return false when newemp is true and only country is undefined and if newemp is false and no field is empty or undefined

function checkObjects(ob){
 var result = ob.some(e=>e.country === true && (Object.keys(e)===undefined))
 return result
}

var resultfor1 = checkObjects(obj1);
var resultfor2 = checkObjects(obj2);
var obj1=[
 {id:1, newemp: true, country: undefined, cardno: 'S05', name: 'sam'},
 {id:2, newemp: false, country: 'IN', cardno: 'S06', name: 'tomy'} 
]

var obj2=[
 {id:3, newemp: true, country: undefined, cardno: 'S05', name: 'ramson'},
 {id:4, newemp: false, country: undefined, cardno: 'S06', name: ' '} 
]


Expected output 

// obj1
False

//obj2
True

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

the objects do not exist at the time you try to use them. you need something like "isLoading" and when ur logic is done then u try to render

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