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

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

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