Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Loop through array of nested objects to check empty string es6

I have an array of nested objects:

const array =[
 { 
    "id": 1,
    "time": { 
       "timezone": "2021-09-22T05:36:22.484Z"
       "city": "Perth"
       "country:: "Australia
       "date": "2021/10/10"
    }
 },
 {
   ​"id": 2,
   ​"time": { 
       "timezone": ​"2021-10-22T03:25:26.484Z"
       "city": ""
       "country: "Americas"
       "date": "2021/10/10"
    }
 },
 {
   ​"id": 3,
   ​"time": { 
       "timezone": ​"2021-09-27T02:43:26.564Z"
       "city": ""
       "country: ""
       "date": "2021/10/10"
    }
 }];

I want to check each value in the time object to see if there exists an empty string without having to have multiple || statements.

What I have tried using lodash:

if(array.find((k)=> _.isEmpty(k.timezone)) || array.find((k)=> _.isEmpty(k.city)) || array.find((k)=> _.isEmpty(k.country)) || array.find((k)=> _.isEmpty(k.date))) {
//do something
 
 } else {
//do something else
 }

This seems to do the trick but trying to find a succinct and cleaner way to do this as there could be more values in the time object, preferably in es6.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Check if .some of the Object.values of any of the time subobjects includes the empty string.

if (array.some(
  k => Object.values(k.time).includes('')
)) {
  // do something
} else {
  // do something else
}
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!