title: Angular to call different variables dynamically Is it possible?
body: <p>Hello I have a function to do a series of tasks on a variable, the thing is that I have to do another function that is exactly the same, only the variable on which it acts changes.</p>
  <p>The question is to reuse and save code. Could it be possible to send the name of the variable in a string to the function and have it use the corresponding variable according to the string received?</p>
  <p>The only way I know is to put both variables in an associative array and pass to the function the name of the corresponding associative key of the array, but I don't think it's &quot;elegant&quot; to create an array just for that and I've never done something like that in any other language either.</p>
  <p>A simple example of what I'm trying to do:</p>
  <p>componente1.component.ts</p>
  <pre><code>   accionComun (nombreVariable: string) {
      
        //  I want to print the variable whose name is the name nombreVariable
        alert();
      
     }
     
     accionComun(&quot;variable1&quot;);
  </code></pre>