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