2016-10-15 3 views
0

ランダムクォートジェネレータを作成しています。すでに表示されている見積もりを配列から削除する方法を理解できないので、ボタンがクリックされたときに2回表示されません。助言がありますか?ここに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; 
} 

ありがとうございます!

+0

:例えば

' array.splice(I、1); ' – ahitt6345

答えて

0

Array.prototype.splice(start, count)機能を使用できます。次のようなスプライス機能をインデックス `i`にある項目を削除することができ

var array = [1, 2, 3, 4, 5] 
// remove 2 in the array. 
var index = 1; 
array.splice(1, 1); 
// array = [1, 3, 4, 5] 
関連する問題