Loop through an array from selected item in angular?

Hi,

I have data and I am looping through an array of objects, I am getting the selected item that is clicked.
I am trying to figure out how to loop through the array of items related to that item that is clicked?

Please help?

Here is my data:

{
        venue_id: 96,
        venue_name: 'name of venue',
        address1: 'somethiing road',
        address2: '',
        address3: '',
        town: 'ths town',
        county: 'xx',
        postcode: 'POSTCODE,
        latitude: 51.665555,
        longitude: -0.360789,
        screeningslist:
            [
                {
                    type: 'Community',
                    screening_code: 'XXXXXX',
                    start_at: '2019-09-09 09:00:00',
                    end_at: '2019-09-09 17:35:00',
                    appointments:
                        [
                            {
                                time: '10:00:00',
                            },
                            {
                                time: '10:20:00',
                            },
                            {
                                time: '11:20:00',
                            },
                            {
                                time: '15:20:00',
                            }
                        ]
                },
                {
                    type: 'Community',
                    screening_code: 'ABC',
                    start_at: '2019-09-09 09:00:00',
                    end_at: '2019-09-09 17:35:00',
                    appointments:
                        [
                            {
                                time: '11:00:00',
                            }
                        ]
                }
            ]
        },

I need to loop through screeningslist

here is my method that selects the venue

onVenueSelect(venue) {
    console.log('marker clicked', venue);
    this.selectedVenue = venue.venue_name;
  }

Find the index, then loop from there. Example:

function loopThroughVenues(venues, selectedVenue) {
  const startIndex = venues.findIndex(venue => venue.venue_name === selectedVenue);

  for (let i = startIndex; i < venues.length; i++) {
    // ....do whatever you want to do
  }

  return something
}

I fixed it! YAY! WOOO

1 Like