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

168
Vistas
checking empty property for array of objects

I wanted to check if there is a property in an array of objects that has a null value , if there is then return true.

Currently my issue is

This condition will always return 'false' since the types '{ type: any; startDate: string; endDate: string; annualRent: any; }' and 'string' have no overlap.ts(2367)

#current code for checking empty property

const hasEmptyRentSchedProperty = Object.values((this.proposedRentSchedule)).some((v => v === null || v === ""))

#object = this.proposedRentSchedule

[
    {
        "type": 0,
        "startDate": "2022-1-4",
        "endDate": "2022-1-19",
        "annualRent": "232"
    },
    {
        "type": 0,
        "startDate": "2022-1-20",
        "endDate": "2022-1-20",
        "annualRent": null
    }
]
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

The reason you get that error is because you are getting the values of array whose type is { type: any; startDate: string; endDate: string; annualRent: any; } and not just string. In this case, how does a string comparison work? That's what Typescript points out.

var data = [
  {
    "type": 0,
    "startDate": "2022-1-4",
    "endDate": "2022-1-19",
    "annualRent": "232"
  },
  {
    "type": 0,
    "startDate": "2022-1-20",
    "endDate": "2022-1-20",
    "annualRent": null
  }
]

console.log(data.some(element => Object.values(element).some(val => val === null || val === "")))

over 4 years ago · Santiago Trujillo 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