• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

183
Views
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 3 years ago · Juan Pablo Isaza
1 answers
Answer question

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 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error