0
Я создаю генератор случайных чисел. Я не могу понять, как удалить уже показанную цитату из массива, чтобы она не отображалась дважды при нажатии кнопки. Какие-либо предложения? Вот 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;
}
Заранее спасибо!
Вы можете удалить элемент с индексом 'i' с функцией сплайсинга как таковой:' Array.splice (I, 1); ' – ahitt6345