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

73
Views
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
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!