Home > Software engineering >  splice method only once
splice method only once

Time:11-03

I have a stepper inside my application when user selects specific options on first step i want to splice some steps from my step array, but i have splice function on button, so everytime i go back and click button again it splices another item, how can i make it splice only once? here is my array of steps:

.ts

this.stepService.steps = [
  FirstStep,
  SecondStep,
  ThirdStep,
  FourthStep,
  SuccessPageComponent
];

nextStep() {

    let value = { ...this.form.value };
         if (value.type == 'once') {
          this.stepService.steps.splice(2, 1);
        }
    
        if (value.type == 'multiple') {
          this.stepService.steps.splice(1, 1);
        }

}

CodePudding user response:

You can use slice() instead.

splice() changes the original array, slice() doesn't but both of them returns array object.

  • Related