title: UUIDV4 in for loop not changing value
body: <p>I am trying to create a function to generate an array of objects with a UUID as the key, as well as a UUID for some of the nested object ids.</p>
  
  <p>Each game will be based on a mock object which I import into the file.</p>
  
  <p>The function expects a sport (string) which will get assigned to a key and a quantity (number) which will determine the for loop iterations.</p>
  
  <p>When using a for loop the UUID for the nested object ids are getting overridden on each iteration.</p>
  
  <pre><code>const mockGame = require('../mock-game');
  const uuidv4 = require('uuid/v4');
  
  function generateMockGames(sport, quantity) {
      let games = []
  
      for (let i = 0; i &lt; quantity; i++) {
          let game = {}
          let id = uuidv4()
  
          game[id] = {
              search: mockGame.search,
              query: mockGame.query,
              variables: mockGame.variables,
          }
  
          game[id].search.eventId = id
          game[id].search.competition.categoryName = sport
  
          game[id].search.id = id
          game[id].search.competition.categoryName = sport;
  
          games.push(game);
      }
  
      return games;
  }
  
  const mockFootballGame = generateMockGames('football', 3);
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>[
    {
      '286c1911-b155-4197-bbde-64dba0b304fe': {
         search: {
             eventId: '286c1911-b155-4197-bbde-64dba0b304fe',
             name: 'test name',
             competition: {
                 categoryName: 'football'
             }
        },
        query: {
             id: '286c1911-b155-4197-bbde-64dba0b304fe',
             competition: {
                 categoryName: 'football'
             }
        },
        variables: {
             name: 'test name'
        }
    },
    {
      '082a46a6-4dde-433d-8011-9e94a5ee79ff': {
         search: {
             eventId: '082a46a6-4dde-433d-8011-9e94a5ee79ff',
             name: 'test name',
             competition: {
                 categoryName: 'football'
             }
        },
        query: {
             id: '082a46a6-4dde-433d-8011-9e94a5ee79ff',
             competition: {
                 categoryName: 'football'
             }
        },
        variables: {
             name: 'test name'
        }
    },
    {
      'ba911751-3ea3-40ab-9bec-c525ab2a07b9': {
         search: {
             eventId: 'ba911751-3ea3-40ab-9bec-c525ab2a07b9',
             name: 'test name',
             competition: {
                 categoryName: 'football'
             }
        },
        query: {
             id: 'ba911751-3ea3-40ab-9bec-c525ab2a07b9',
             competition: {
                 categoryName: 'football'
             }
        },
        variables: {
             name: 'test name'
        }
    }
  ]
  </code></pre>
  
  <p>Output is:</p>
  
  <pre><code>[
    {
      '286c1911-b155-4197-bbde-64dba0b304fe': {
         search: {
             eventId: 'ba911751-3ea3-40ab-9bec-c525ab2a07b9',
             name: 'test name',
             competition: {
                 categoryName: 'football'
             }
        },
        query: {
             id: 'ba911751-3ea3-40ab-9bec-c525ab2a07b9',
             competition: {
                 categoryName: 'football'
             }
        },
        variables: {
             name: 'test name'
        }
    },
    {
      '082a46a6-4dde-433d-8011-9e94a5ee79ff': {
         search: {
             eventId: 'ba911751-3ea3-40ab-9bec-c525ab2a07b9',
             name: 'test name',
             competition: {
                 categoryName: 'football'
             }
        },
        query: {
             id: 'ba911751-3ea3-40ab-9bec-c525ab2a07b9',
             competition: {
                 categoryName: 'football'
             }
        },
        variables: {
             name: 'test name'
        }
    },
    {
      'ba911751-3ea3-40ab-9bec-c525ab2a07b9': {
         search: {
             eventId: 'ba911751-3ea3-40ab-9bec-c525ab2a07b9',
             name: 'test name',
             competition: {
                 categoryName: 'football'
             }
        },
        query: {
             id: 'ba911751-3ea3-40ab-9bec-c525ab2a07b9',
             competition: {
                 categoryName: 'football'
             }
        },
        variables: {
             name: 'test name'
        }
    }
  ]
  
  </code></pre>