vendredi 10 mars 2017

randomize objects in array

I have an array that is rendering 25 images/pins every time a button is clicked, and it is only rendering the first 25 in the array. I want it to render 25 pins at a time but would like them to be random every time the button is clicked.

It was suggested I use part of an answer previously set in here, but I cannot figure out how to apply it or make sense of what I have.

This is what I was told to use: randomIndex = Math.floor(Math.random() * currentIndex);

And replace current index with the array I want plus .length.

var pinIdArray = ["448460075380400214", "554857616577037440", "129619295506364205"];                                    
var boardIdArray = [];
var showPins = [];
      
function(){
  res.render("suggested", {pins: showPins});

Aucun commentaire:

Enregistrer un commentaire