0

How to call the variables base on the parameters pass.

public array1: Array<any> = ['list', 'of','array1'];
public array2: Array<any> = ['list', 'of','array2'];
public array3: Array<any> = ['list', 'of','array3'];
public array4: Array<any> = ['list', 'of','array4'];
public array5: Array<any> = ['list', 'of','array5'];
public array6: Array<any> = ['list', 'of','array6'];

         
    ngOnInit(): void {

     this.useArray(param);

    }

   useArray(param) {

      //if param is array6

      passTheArray(this.array6);

   }

This array will be passed to another service to process it.

1 Answer 1

1

You can use the bracket notation to access the elements.

See the code below.

useArray(param) {

    //if param is array6

    passTheArray(this[param]);

}
Sign up to request clarification or add additional context in comments.

1 Comment

this is really what I'm looking for.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.