title: How can I use a new version of an object in a loop, without it getting overriden?
body: <p>I have a function that loops over an array of words, and checks if a string passed to the function contains any of the letters in the word. The word with the most matching letters is returned. </p>
  
  <p>My issue is that the <code>const</code> I am copying to the loop scope is getting overriden. Specifically <code>let loopIndex = alphabetIndex;</code> How can I make a variable that I can manipulate in the loop, without it overriding the <code>const</code>?</p>
  
  <pre><code>import _forEach from 'lodash/foreach';
  const dictionary = require('./dictionary.json');
  
  /**
   * @constructor
   */
  var Game = function () {
  };
  
  /**
   * @desc Return an object of the repeating string characters.
   * @param string
   * @returns {{}}
   */
  Game.prototype.setAlphabet = function (string) {
    let alphabet = {};
    for (let i = 0; i &lt; string.length; i += 1) {
      if (string[i] in alphabet) {
        alphabet[string[i]] += 1;
      } else {
        alphabet[string[i]] = 1;
      }
    }
    return alphabet;
  };
  
  /**
   * @desc Return the largest word using the string passed to the function.
   * @param string
   */
  Game.prototype.getWinningWord = function (string) {
    let max      = 0;
    let maxIndex = 0;
  
    // Get the amount of letters used in the string as an object.
    const alphabetIndex = this.setAlphabet(string);
  
    // Loop through every word in the dictionary
    _forEach(dictionary, function (word, position) {
      let sum       = 0;
      let loopIndex = alphabetIndex;
      // For each of the letters, check the index; and if the letter exists in the word, add to the sum.
      for (let i = 0; i &lt; word.length; i += 1) {
        if (loopIndex[word[i]] &gt; 0) {
          sum += 1;
          loopIndex[word[i]] -= 1;
        }
      }
      // If the current word has more matching letters than the previous max, set this word to max.
      if (sum &gt; max) {
        max      = sum;
        maxIndex = position;
      }
      if (position &gt; 10) return false;
    });
    return dictionary[maxIndex];
  };
  
  /**
   * Init game.
   * @type {Game}
   */
  var newGame = new Game();
  console.log(newGame.getWinningWord('eeosnndsm'));
  </code></pre>