0

I have an array of arrays. I'm attempting to use a single method to split the inner arrays into their own lists. I'm passing in a parameter which is a property name of the outer array (and the name of each inner array).

  getEnrollmentItem(item: string) {
    const list = [];
    Enrollments.forEach((enrollment) => {
      list.push(enrollment.item);
    });

Calling the method, passing in the parameter item:

planList = this.enrollmentService.getEnrollmentItem('plans');

Sample nested array:

export const Enrollments [
    {
        enrollmentId: 1,
        plans: [
            { planName: 'Plan A', carrierName: 'Medical Mutual' },
            { planName: 'Plan XYZ', carrierName: 'United Healthcare' }
        ],
        employees: [
            { employeeName: 'Ben', relationship: 'Primary' },
            { employeeName: 'Lauren', relationship: 'Spouse' },
        ]
    },
    {
        enrollmentId: 2,
        plans: [{ planName: 'Plan 99', carrierName: 'GoodHealth' }],
        employees: [{ employeeName: 'Enrollment 2 Employee', relationship: 'Primary' },]
    }
];

Obviously what I'm attempting doesn't compile, as there is no "item" property of the enrollment array. Is there a way to pass in something that can then be used as this property?

noclist
  • 1,659
  • 2
  • 25
  • 66

0 Answers0