title: Javascript Uncaught TypeError: Cannot read property '0' of undefined using a for loop to search an array
body: <p>I am working on a project where I make a table in HTMl and than draw the table in javascript using a 2D Array. Then I made a function that finds a * and makes them into letters where other * are touching it. Than once that is done is changes the letter to B and finds the next * in the array and makes all * touching it into B and so on. My problem is that my loop that finds all the * in the array comes up with an error. Any suggestions?</p>
  
  <pre><code> var organismArray = [
      ["*","*","_"],
      ["-","_","*"],
      ["-","*","*"]
  ]; 
  
  function drawOrganism() {
      var letter = 'A';
      var Organisms = 0;
      for (var col = 0; col &lt; 2; col++) {
          for (var row = 0; row &lt; 2; row++) {
              if (organismArray[col][row] == "*") { // This is where the Error occurs.
                  organismArray = howManyOrganisms(col, row, letter);
                  letter++;
                  Organisms++;
  
  
              }`
          }
      }
      console.log(organismArray);
  }
  function howManyOrganisms(col,row,letter) {
      organismArray[col][row] = letter;
  
  
      if (col + 1 &lt; organismArray.length) {
          if (organismArray[col + 1][row] == "*") {
              howManyOrganisms(col + 1, row, letter);
          }
      }
      if (col - 1 &gt;= 0) {
          if (organismArray[col - 1][row] == "*") {
              howManyOrganisms(col-1, row, letter);
          }
      }
      if (row - 1 &gt;= 0) {
          if (organismArray[col][row - 1] == "*") {
              howManyOrganisms(col, row - 1, letter);
          }
      }
      if (row + 1 &lt; organismArray[col].length) {
          if (organismArray[col][row + 1] == "*") {
              howManyOrganisms(col, row + 1, letter);
          }
      }
  }
  </code></pre>