Please consider explanation from comments. [Array.prototype.splice()][1]
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-js -->
var links = ["page-1", "page-2", "page-3", "page-108"];
// array to hold used link values which are removed form links.
// when links is empty then assign all values back from linksUsed and clear linksUsed.
var linksUsed = [];
function openSite() {
// if links is empty then assign all values back from linksUsed and clear linksUsed.
if (links.length == 0) {
links = linksUsed;
linksUsed = [];
}
var randIdx = Math.random() * links.length;
randIdx = parseInt(randIdx, 10);
// splice will remove n items starting from index.
// First parameter value is starting index and 2nd parameter is delete count
var link = links.splice(randIdx, 1)[0];
// push removed link to linksUsed
linksUsed.push(link);
// update link
link = 'https://websitename.com/page/' + link;
// for testing commented below line and added log
// window.location.assign(link);
console.log(link);
};
for (let i = 0; i < 5; i++) {
openSite();
}
<!-- end snippet -->
[1]: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/splice