I was wondering if there was any way to get a value of an array, based on a string, and display the next value in the array.
<p id="current">page1</p>
<p id="next"></p>
<script>
var page = ["page1", "page2", "page3", "page4", "page5"];
if(document.getElementById("current") == page[0]){
document.getElementById("next").innerhtml = page[1]
};
</script>
That's what I have as the general idea. However, it would be a lot of if statements, and it wouldn't look pretty. So I was wondering if there would be a way to replicate this sort of function, without it including too many if statements.
page[1]. Or use a loop to see what page is the current page and then the next item in the array is the next page.document.getElementById("next").innerhtml = page[++page.indexOf(document.getElementById("current").innerhtml)]?