title: How do I remove "undefined" from the beginning of JavaScript array items?
body: <p>I'm trying to generate an array of random digits, but I'm getting "undefined" at the beginning of each row. I've been searching online for a couple of hours, but haven't been able to figure it out.</p>
  
  <p>The expected output should be 5 rows of 2 random digits like this:</p>
  
  <pre><code>87
  57
  81
  80
  02
  </code></pre>
  
  <p>but the actual output looks like this:</p>
  
  <pre><code>undefined87
  undefined57
  undefined81
  undefined80
  undefined02
  </code></pre>
  
  <p>This is a modified excerpt that produces the result shown above:</p>
  
  <pre><code>function NumberSet() {
  
    // generate all the digits
    this.generate = function() {
      random_digits = [];
  
      // create 5 rows of 2 random digits
      for(i=0; i&lt;5; i++) {
        for(z=0; z&lt;2; z++) {
          // use .toString() in order to concatenate digits to 
          // the array without adding them together
          random_digit = Math.floor(Math.random()*10).toString();
          random_digits[i] +=random_digit;
        }
      }
      return random_digits;
    }
  }
  randomnumbers1 = new NumberSet();
  mynums = randomnumbers1.generate();
  jQuery.each(mynums, function(i, l) {
    // display output in a div#nums
    $('#nums').append(l + '&lt;br&gt;');
  });
  </code></pre>
  
  <p>The final version won't be using this method to display the digits. I'm just trying to troubleshoot where the "undefined" is coming from.</p>