How can I shuffle an array\'s values in the most efficient manner possible?
Each element is just a string containing HTML.
You have a few choices.
First, you could use the stupidely naïve sorter...
arr = arr.sort(function() {
return Math.random() - .5
});
jsFiddle.
This is quick and dirty but often considered bad practice.
Further Reading.
The best way to randomly sort an Array is with the Fisher-Yates shuffle.
var newArr = [];
while (arr.length) {
var randomIndex = Math.floor(Math.random() * arr.length),
element = arr.splice(randomIndex, 1)
newArr.push(element[0]);
}
JSBin.