title: Uncaught TypeError: Cannot set property '1' of undefined
body: <p>Now this is wierd, I basically calling the function "sortTiles()" twice,  the first time, it loops through, and returns a beautiful array, just as it's supposed to do. But the second time I call it, it doesn't work, and throws the error as stated in the title to a specific line: <strong><em>tiles[y][x] = tile;</em></strong>.</p>
  
  <p>The first time around, the returned array from "sortTiles()" is put into a global array called "solution". The second time the function is called, it will get the tiles X and Y coordinate from the solution array.</p>
  
  <p>What I'm doing here is it basically scans a sliding puzzle, with the help of a html5 canvas and prnt_scrn+paste into the website. And as said, first time you do it, you take a screenshot of the solution, paste it in, and it marks out all the coordinates just fine. The second time, it throws an error :(</p>
  
  <pre><code>function getTile(x, y) {
      var id = 0;
      for (i = 0; i &lt; 2; i++) {
          for (i2 = 0; i2 &lt; 2; i2++) {
              var data = context.getImageData(x + i * 48 + 5 - (i * 10), y + i2 * 48 + 5 - (i2 * 10), 1, 1).data;
              id += data[0] + data[1] + data[2];
          }
      }
      return id;
  }
  
  function findTile(number) {
      for (y = 0; y &lt; 5; y++) {
          for (x = 0; x &lt; 5; x++) {
              if (solution[y][x] == number) {
                  return [x, y];
              }
          }
      }
  }
  
  function sortTiles() {
      context.font = "20px Georgia";
      var tiles = [];
      tiles.length = 0;
      for (y = 0; y &lt; 5; y++) {
          tiles[y] = [];
          for (x = 0; x &lt; 5; x++) {
              var tile = getTile(108 + x * 56, 34 + y * 56);
              tiles[y][x] = tile;
              if (solution.length != 0) {
                  var coordinate = findTile(tile);
                  context.fillText(coordinate[0] + ", " + coordinate[1], 108 + x * 56 + 12, 34 + y * 56 + 36);
              } else {
                  context.fillText(x + ", " + y, 108 + x * 56 + 12, 34 + y * 56 + 36);
              }
          }
      }
      return tiles;
  }
  </code></pre>