title: How can I set a local variable using a string?
body: <p>I need to set a local variable inside a for loop in a function, but part of the name of this var needs to be a string, more specifically an array index. </p>
  
  <p>See the example:</p>
  
  <pre><code>function MyFunction () {
      var strings = ["first","second","third","fourth"];
  
      for (var i = 0; i &lt; strings.length; i++) {
          var "My_" + strings[i] + "_var" = "Hi, I'm the " + strings[i] + " var!";
      }
  }
  </code></pre>
  
  <p>I know this is not the correct way, I'm just illustrating what I want to do. I've already tried using <code>window[]</code> or <code>this[]</code>, but seems like the var becomes global.</p>