How can I prevent the repetition of index values when switching between previous and next buttons while displaying 15 posts each time?
For example, currently when clicking on the next button and reaching an index value of 5, then clicking on prev shows the index at value 5 again before decrementing. How do I avoid this behavior?
var array = [0,1,2,3, ...,50]
var index = 0
var button = document.querySelectorAll("button").addEventListener("click",paginate)
paginate(e) {
var target = e.currentTarget.dataset.button,
postsPerPage = 15,
posts = array.length,
total = Math.ceil(posts / postsPerPage),
index = target === 'next' ? index++ : --index,
//...
}