Jquery - Select random JSON Object

后端 未结 2 1470
别跟我提以往
别跟我提以往 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条回答
  •  [愿得一人]
    2021-01-25 12:08

    $.getJSON('b.json', function(data) { 
      var entry = data[Math.floor(Math.random()*data.length)];
      //do the same exact thing with entry
    }
    

提交回复
热议问题