title: Uncaught Typeerror,Cannot read property '1' of undefined
body: <p>I have been doing some coding for class and I ran into a problem whilst coding for a traffic light system. Here is my code, the error is apparently around 21 and 22 and is an 'Uncaught Typeerror'. Could you please show me a few tips?</p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
      &lt;script&gt;
          var trafficlights [ "red.png", "orange.png", "green.png"];
          var index = 0;
  
          function traffic() { // this part is tricky
              index = index + 1;
              if (index == index.length) 
                  index = 0;
  
              var image = document.getElementById('light')[0];
              image.src = trafficlights[index].value = data;
          }
      &lt;/script&gt;
  
      &lt;img id="light" src="red.png" style="width:250px;height:250px;"&gt;
      &lt;button type="button" onclick= "traffic()"&gt;click to change lights&lt;/button&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>