I am encountering an issue with checking for undefined and empty strings in an object array using Javascript. The code provided is partly functional, but I have hit a roadblock.
Within the array object,
If the field value is undefined or empty, it should only return true when newemp is false.
If all fields except country are undefined or empty, it should only return true when newemp is true.
Otherwise, it should return false if newemp is true and only country is undefined, or 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