title: Is there a more efficient way of doing this code without if statements?
body: <p>I have made this code that uses the set interval function to go through an array.</p>
  
  <pre><code>&lt;img src="red.jpg" id="traffic" width="155" height="198"&gt;
  
  &lt;script&gt;
  
  var imgarray = ["red.jpg", "redandorange.jpg", "green.jpg", "orange.jpg"]
  document.getElementById("traffic").innerHTML = traffic;
  
  setInterval(function () {
  ChangeLights() ;
  }, 2000) ;
  
  function ChangeLights() { 
  if (traffic.src.match(imgarray[0])){
  traffic.src = imgarray[1];
  }else if (traffic.src.match(imgarray[1])){
  traffic.src = imgarray[2];
  }else if (traffic.src.match(imgarray[2])){ 
  traffic.src = imgarray[3];
  }else if (traffic.src.match(imgarray[3])){ 
  traffic.src = imgarray[0];
  }}
  </code></pre>
  
  <p>Is there a way to do it without all of the if statements?</p>