title: How would I return an array of modified objects without returning the original objects?
body: <p>I am making a random maze generator and I have gotten everything to work, except for the return statement. My original plan for this in the end is to be able to test some maze solving algorithms on this, so displaying it is nice, which it does, but having access to the maze as code is a necessity. The function itself modifies the objects in the array and works, but when returned, the objects are all in their original state.</p>
  
  <pre><code>//This is the code with the irrelevant stuff removed
  function generate() {
    var maze = []
    for(let y = 0; y &lt; tiles[1]; y++) {
      let tempArr = [];
      for(let x = 0; x &lt; tiles[0]; x++) {
        //l,u,r,and d are all whether or not you can pass through that side of the tile, v is whether or not the tile has been visited by the actual generation
        tempArr.push([{l:true,u:true,r:true,d:true,v:false}]);
      }
      maze.push(tempArr);
      //After this point, the array that is returned does not change
    }
  
    //Builds the walls on the edge of the square
    for(let y = 0; y &lt; maze.length; y++) {
      for(let x = 0; x &lt; maze[y].length; x++) {
        if(y == 0) {
          maze[y][x].u = false;
        }
        if(x == 0) {
          maze[y][x].l = false;
        }
        if(y == tiles[1]-1) {
          maze[y][x].r = false;
        }
        if(x == tiles[0]-1) {
          maze[y][x].d = false
        }
      }
    }
  
    let _x = 0;
    let _y = 0;
  
    for(let i = 0; i &lt; tiles[0]*tiles[1]; i++) {
      //None of these changes are visible in the returned array
      maze[_y][_x].v = true;
      let running = true;
      while(running) {
        maze[_y][_x].v = true;
        let random = Math.floor(Math.random()*4)+1;
        if(random == 1) {//This is repeated for 2, 3, and 4
          if(maze[_y][_x-1] &amp;&amp; !maze[_y][_x-1].v) {
            maze[_y][_x].l = true;
            maze[_y][_x-1].r = true;
            _x -= 1;
            continue;
          } else if(maze[_y][_x+1] &amp;&amp; !maze[_y][_x+1].v) {
            maze[_y][_x].r = true;
            maze[_y][_x+1].l = true;
            _x += 1;
            continue;
          } else {
            random++
          }
        }
      }
    }
  
    return maze; //This returns the original array, regardless of any changes made
  }
  </code></pre>
  
  <p>This does not get me any errors, but in the case of a 3 x 3 maze I would expect a result of:</p>
  
  <pre><code>[[{u:false,l:false,d:false,r:true,v:true}],[{u:false,l:true,d:false,r:true,v:true}],[{u:false,l:true,d:true,r:false,v:true}]],
  [[{u:false,l:false,d:true,r:true,v:true}],[{u:false,l:true,d:false,r:true,v:true}],[{u:true,l:true,d:false,r:false,v:true}]],
  [[{u:true,l:false,d:false,r:true,v:true}],[{u:false,l:true,d:false,r:true,v:true}],[{u:false,l:true,d:false,r:false,v:true}]]
  </code></pre>
  
  <p>but get an array consisting of only:</p>
  
  <pre><code>{d:true,l:true,r:true,u:true,v:false} 
  </code></pre>