Keeping Track of Current Image Index with a JavaScript Variable

2 months ago
5

Learn how to keep track of the current image index using a JavaScript variable.

In order to allow for multiple images to be browsed through as you click the next button, you have to know which image URL to use to display the image. Since the URLs are held in an array, you can take the next element every time you click next.

In order to remember what image the user is seeing, you have to store its index in a variable. Then, every time you click the next button, that index is incremented and eventually you see the next image in the list.

Loading 2 comments...