0

I want to remove or delete all object where inspectionScheduleQuestionId is null , how do we address this in JS ?

Thanks.

#data

const data = [
    {
        "id": 0,
        "inspectionScheduleQuestionId": 1,
        "inspectionScheduleConfirmationId": 0,
        "description": "65"
    },
    {
        "id": 0,
        "inspectionScheduleQuestionId": 10,
        "inspectionScheduleConfirmationId": 0,
        "description": "656"
    },
    {
        "id": 0,
        "inspectionScheduleQuestionId": null,
        "inspectionScheduleConfirmationId": 0,
        "description": 6
    },
    {
        "id": 0,
        "inspectionScheduleQuestionId": null,
        "inspectionScheduleConfirmationId": 0,
        "description": 21
    },

]
2
  • 1
    What have you attempted to address this? SO isn't a coding service. Commented Apr 22, 2022 at 17:31
  • sorry forgot to add , adding it now Commented Apr 22, 2022 at 17:31

2 Answers 2

1

You can use filter for this:

const updatedData = data.filter(item => item.inspectionScheduleQuestionId !== null);

Here's some more information on Array.prototype.filter.

Sign up to request clarification or add additional context in comments.

Comments

0
new data = data.filter(d => d.inspectionScheduleQuestionId)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.