Javascript infinite next in shuffled JSON

I have dual languages JSON, which is shuffled on start. I want to make it start again if index of JSON is equal to maximum index by pressing button. But I’m stuck here since I’m not really familiar with JavaScript. Please help to make it so that clicking on the WINE button returns to the beginning of shuffled JSON.

// Detect language into variable and log it
var userLang = navigator.language || navigator.userLanguage; 
console.log("The browser language is: " + userLang);

var alcoscroll = {
    "wine": [{
        "en": "Wine Drink 1",
        "es": "Vino 1",
    }, {
        "en": "Drink 2",
        "es": "Vino 2",
    }, {
        "en": "Drink 3",
        "es": "Vino 3",
    }, {
        "en": "Drink 4",
        "es": "Vino",
    }]
};

alcoscroll.wine.sort(function (alcoscroll) {return Math.random() - 0.5;}); // Sort alcoscroll
console.log(alcoscroll);

var index = 0; // Starting index of JSON object
var maxx  = alcoscroll.wine.length-1; // Max ID number (JSON index number)
var item = alcoscroll.wine[index]; // Current index sniffer
var next = document.getElementById('refbtn'); // Button to move to next one

displayItem(item);

next.addEventListener('click', function() {
    displayItem(alcoscroll.wine[++index]);
});

console.log("MAXIndex is: " + maxx)

function displayItem(item) {
// Catch item number into function ERROR HERE
intitem = alcoscroll.wine[index];
console.log("INT item is: " + intitem);

// English or Spanish radical choice
if (userLang === "en-US") {
title.innerText = item.en;
} else {
title.innerText = item.es;
}
    console.log("Index is: " + index)
    
    if (intitem == maxx) { // If it's the last index of JSON object ERROR HERE
    console.log("LAST")
    next.addEventListener('click', function() {
    intitem = 0; // Current index sniffer ERROR HERE
});
    } else
    {console.log("NOT last")}
}
<div class="container">
  <div>
    <div id="title"></div>
  </div>
  <button id="refbtn">WINE</button>
</div>

Answer

The problem is in this piece of code:

if (intitem == maxx) { // If it's the last index of JSON object ERROR HERE
    console.log("LAST")
    next.addEventListener('click', function() {
        intitem = 0; // Current index sniffer ERROR HERE
    });
} 

You’re comparing intitem to maxx when you should be comparing index to maxx. Also, you don’t need to add another event listener, you should just reset the index value. Change it to:

if (index == maxx) { // If it's the last index of JSON object ERROR HERE
    console.log("LAST");
    index = -1; // Index should be -1 because it's incremented before getting
                // the item.
} 

Here’s the updated snippet:

// Detect language into variable and log it
var userLang = navigator.language || navigator.userLanguage; 
console.log("The browser language is: " + userLang);

var alcoscroll = {
    "wine": [{
        "en": "Wine Drink 1",
        "es": "Vino 1",
    }, {
        "en": "Drink 2",
        "es": "Vino 2",
    }, {
        "en": "Drink 3",
        "es": "Vino 3",
    }, {
        "en": "Drink 4",
        "es": "Vino",
    }]
};

alcoscroll.wine.sort(function (alcoscroll) {return Math.random() - 0.5;}); // Sort alcoscroll
console.log(alcoscroll);

var index = 0; // Starting index of JSON object
var maxx  = alcoscroll.wine.length-1; // Max ID number (JSON index number)
var item = alcoscroll.wine[index]; // Current index sniffer
var next = document.getElementById('refbtn'); // Button to move to next one

displayItem(item);

next.addEventListener('click', function() {
    displayItem(alcoscroll.wine[++index]);
});

console.log("MAXIndex is: " + maxx)

function displayItem(item) {
// Catch item number into function ERROR HERE
intitem = alcoscroll.wine[index];
console.log("INT item is: " + intitem);

// English or Spanish radical choice
if (userLang === "en-US") {
title.innerText = item.en;
} else {
title.innerText = item.es;
}
    console.log("Index is: " + index)
    
    if (index == maxx) { // If it's the last index of JSON object ERROR HERE
    console.log("LAST");
    index = -1; // Current index sniffer ERROR HERE
    } else
    {console.log("NOT last")}
}
<div class="container">
  <div>
    <div id="title"></div>
  </div>
  <button id="refbtn">WINE</button>
</div>