Reputation: 1151
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.
Upvotes: 0
Views: 20
Reputation: 2755
You can use the bracket notation to access the elements.
See the code below.
useArray(param) {
//if param is array6
passTheArray(this[param]);
}
Upvotes: 1