Jquery - Select random JSON Object

后端 未结 2 1500
别跟我提以往
别跟我提以往 2021-01-25 11:27

I have this jquery code to output the entries in a JSON file on page load...

$.getJSON(\'b.json\', function(data) {
      $(\'#dictionary\').empty().hide();



          


        
2条回答
  •  闹比i
    闹比i (楼主)
    2021-01-25 11:57

    Looks like you want a random entry from an array.

    try:

    var random_entry = entry[Math.floor(Math.random() * entry.length)]
    

提交回复
热议问题