ianh11
ianh11

Reputation: 147

Angular delete object at index in stepperArray

Before I make this API call I need to remove the product that contains a selectedPlan value of null. I am unsure as to why the below is not working. Do I need reassignment of stepper array before passing as parameter in startEnrollment()?

startEnrollment(stepperArray: MhnStartEnrollmentRequest[]) {
        stepperArray.forEach(value => {
          if (value.selectedPlan === null) {
            delete stepperArray[value.productId]
          }
        });
        stepperArray.values();
        return this.mhnApiClientService.startEnrollment(stepperArray, this.quoteId, this.clientId);
      }

enter image description here

Upvotes: 0

Views: 39

Answers (1)

Akhilesh
Akhilesh

Reputation: 76

Your accessing product to delete by value.productId instead of its actual index in the array

And instead of deleting it which just makes the value at that index undefined use filter

const enrolmentsWithAPlan = stepperArray.filter(value => value.selectedPlan !== null);

Upvotes: 1

Related Questions