how to filter array of object in Javascript es6

I want to filter items from the schedule variable based on "isPackageIncluded" "isPackageIncluded": 1 then only the data that is "isPackageIncluded": 1 is displayed if the data is not displayed, I have tried filtering it but it still doesn’t work,all data remains displayed, what is the solution for this case, please help, thank you

let schedule = [
    {
         "tempRfpScheduleId": "12345",
         "package": {
             "tempRfpSchedulePackageId": "888",
             "totalAttendees": 0
          },
          "food": [
              {
                  "tempRfpScheduleFoodId": "123",
                  "foodName": "Test",
                  "quantity": 0,
                  "isPackageIncluded": 1
               },
               {
                   "tempRfpScheduleFoodId": "456",
                   "foodName": "Coffee Break",
                   "quantity": 0,
                   "isPackageIncluded": 0
                }
           ],
           "accomodation": [
                {
                    "tempRfpScheduleAccomodationId": "111",
                    "quantity": 0,
                    "isPackageIncluded": 1
                },
                {
                     "tempRfpScheduleAccomodationId": "222",
                     "quantity": 0,
                     "isPackageIncluded": 0
                }
           ]

    },
    {
         "tempRfpScheduleId": "67890",
         "package": {
             "tempRfpSchedulePackageId": "999",
             "totalAttendees": 0
          },
          "food": [
              {
                  "tempRfpScheduleFoodId": "1122",
                  "quantity": 0,
                  "isPackageIncluded": 0
               },
               {
                   "tempRfpScheduleFoodId": "3344",
                   "quantity": 0,
                   "isPackageIncluded": 1
                }
           ],
           "accomodation": [
                {
                    "tempRfpScheduleAccomodationId": "444",
                    "quantity": 0,
                    "isPackageIncluded": 0
                },
                {
                     "tempRfpScheduleAccomodationId": "555",
                     "quantity": 0,
                     "isPackageIncluded": 1
                }
           ]

    }
]

Expected result

schedule = [
    {
         "tempRfpScheduleId": "12345",
         "package": {
             "tempRfpSchedulePackageId": "888",
             "totalAttendees": 0
          },
          "food": [
              {
                  "tempRfpScheduleFoodId": "123",
                  "foodName": "Test",
                  "quantity": 0,
                  "isPackageIncluded": 1
               }
           ],
           "accomodation": [
                {
                    "tempRfpScheduleAccomodationId": "111",
                    "quantity": 0,
                    "isPackageIncluded": 1
                }
           ]

    },
    {
         "tempRfpScheduleId": "67890",
         "package": {
             "tempRfpSchedulePackageId": "999",
             "totalAttendees": 0
          },
          "food": [
               {
                   "tempRfpScheduleFoodId": "3344",
                   "quantity": 0,
                   "isPackageIncluded": 1
                }
           ],
           "accomodation": [
                {
                     "tempRfpScheduleAccomodationId": "555",
                     "quantity": 0,
                     "isPackageIncluded": 1
                }
           ]

    }
]

this lies in a function, but the results are not as expected, do I have to loop the array first and then filter it after the array is looped?

 const _handleSubmit = event => {
    event.preventDefault()
    schedule.map((item, index) => {
      item.food.map(itemFood => itemFood.isPackageIncluded > 0)
      item.accomodation.map(itemAccomondation => itemAccomondation.isPackageIncluded > 0)
    })
  }

``

Answer

You were close. In your map(), item is each array element, so you don’t need to use the [index] bit. Next, you were correct, filter() inside the map. But you’ll need to assign the original item.food and item.accomodation with the filtered values.

Here you go:

let schedule = [{"tempRfpScheduleId":"12345","package":{"tempRfpSchedulePackageId":"888","totalAttendees":0},"food":[{"tempRfpScheduleFoodId":"123","foodName":"Test","quantity":0,"isPackageIncluded":1},{"tempRfpScheduleFoodId":"456","foodName":"Coffee Break","quantity":0,"isPackageIncluded":0}],"accomodation":[{"tempRfpScheduleAccomodationId":"111","quantity":0,"isPackageIncluded":1},{"tempRfpScheduleAccomodationId":"222","quantity":0,"isPackageIncluded":0}]},{"tempRfpScheduleId":"67890","package":{"tempRfpSchedulePackageId":"999","totalAttendees":0},"food":[{"tempRfpScheduleFoodId":"1122","quantity":0,"isPackageIncluded":0},{"tempRfpScheduleFoodId":"3344","quantity":0,"isPackageIncluded":1}],"accomodation":[{"tempRfpScheduleAccomodationId":"444","quantity":0,"isPackageIncluded":0},{"tempRfpScheduleAccomodationId":"555","quantity":0,"isPackageIncluded":1}]}]

let out = schedule.map((item, index) => {
  item.food = item.food.filter(itemFood => itemFood.isPackageIncluded > 0)
  item.accomodation = item.accomodation.filter(itemAccomondation => itemAccomondation.isPackageIncluded > 0)
  return item;
})

console.log(out);