JSFiddle - React, Tailwind, and code Playground
HTML
<div id="array" class="thirdcanvas"></div>
<button class="array">Shuffle</button>
JavaScript
var arr = new Array("http://static3.businessinsider.com/image/52cddfb169beddee2a6c2246/the-29-coolest-us-air-force-images-of-the-year.jpg", "http://blog.gettyimages.com/wp-content/uploads/2013/01/Siberian-Tiger-Running-Through-Snow-Tom-Brakefield-Getty-Images-200353826-001.jpg", "http://blog.jimdo.com/wp-content/uploads/2014/01/tree-247122.jpg", "http://www.picturesnew.com/media/images/images-background.jpg", "http://static.ddmcdn.com/gif/storymaker-best-hubble-space-telescope-images-20092-514x268.jpg", "http://ichef.bbci.co.uk/wwfeatures/624_351/images/live/p0/1p/5y/p01p5ygs.jpg", "http://blog.gettyimages.com/wp-content/uploads/2012/10/81076116-Chip-Somodevilla-Getty-Images-e1351541533518.jpg");
$('button.array').on('click', function(){
shuffle(arr);
var firstFive = arr.slice(0, 5);
$('#array').empty();
$.each(firstFive, function(i,v){
console.log(v);
$('#array').append('<img src="'+v+'">');
});
});
function shuffle(array) {
var currentIndex = array.length
, temporaryValue
, randomIndex
;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}