title: JavaScript change img src
body: <p>I am trying to make an image slider just using JavaScript. I have a button with an id in HTML and want to change the src of the button based on a position in an array. This is my following code. </p>
  
  <pre><code>var index = 0;
  var imageArray = [{'images/img1.jpg'},{'images/img2.jpg'},{'images/img3.jpg'},{'images/img4.jpg'}];
  
  function moveToNextSlide()
  {
      if (index &gt;= imageArray.length -1)
      {
          index =-1;
      }
      var img = getElementById(img_start);
      index = index + 1;
      var currentSlide = imageArray[index];
      getElementByid(img_start).src="currentSlide";
  
  }
  </code></pre>