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

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

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