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

74
Vistas
Return null if property in object mapped is undefined

I have a nested object and I have a function that should return an array of ids if they exist, or undefined if not

The problem with my code is that it returns [null] instead of null when siteIds property is null

const getContractSites = (state: AppStateType) => state.dashboard.contractAttendanceTable
export const getSites = createSelector(getContractSites, data => {
    const test =  data.map(attendance => {
        console.log(attendance)
        if (!attendance.dayShiftAttendance.siteIds) return null
        return attendance.dayShiftAttendance.siteIds.map(siteId => {
            return {"value": siteId}
        })
    })

    console.log(test)
    return test
})

This is a mock for my object

 {
                    "dayShiftAttendance": {
                        "entityType": "SITE",
                        "entityId": 12792,
                        "entityName": "Smoke test 8th april",
                        "siteIds": null,
                        "postIds": [
                            36624,
                            36625,
                            36645
                        ],
                        "timeShift": "Day",
                        "contracted": 600,
                        "attend": 0,
                        "late": 0,
                        "unattended": 0,
                        "upcoming": 0
                    },
                    "nightShiftAttendance": {
                        "entityType": "SITE",
                        "entityId": 12792,
                        "entityName": "Smoke test 8th april",
                        "siteIds": null,
                        "postIds": [
                            36624,
                            36625,
                            36645
                        ],
                        "timeShift": "Night",
                        "contracted": 0,
                        "attend": 0,
                        "late": 0,
                        "unattended": 0,
                        "upcoming": 0
                    }
                }
about 4 years ago · Santiago Gelvez
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