0

I am building a random quote generator. I can not figure out how to remove an already shown quote from the array so it does not show up twice when the button is clicked. Any suggestions? Here is the javascript:

 var quoteArray = [
        {
            content: "quote 1 goes in here",
            author: "author 1"
        },
        {
            content: "quote 2 goes in here",
            author: "author 2"
        }
        ];

    var button = document.getElementById('quote-button'),
        quote = document.getElementById('quote'),
        author = document.getElementById('quote-author'),
        random;

window.onload = randomQuote;
button.addEventListener('click', randomQuote);

function randomQuote (){
    random = Math.floor(Math.random() * quoteArray.length);
    quote.innerHTML = quoteArray[random].content;
    author.innerHTML = '— ' + quoteArray[random].author;
}

Thanks in advance!

1 Answers1

0

You can use Array.prototype.splice(start, count) function.

For example:

var array = [1, 2, 3, 4, 5]
// remove 2 in the array.
var index = 1;
array.splice(1, 1);
// array = [1, 3, 4, 5]
Micheal_Song
  • 119
  • 1
  • 7