Random Shuffle Javascript Array

Shuffle a javascript array in random order. Pass the array into the function. The function returns the array shuffled in random order.

function shuffleRandom(a) {
    for (var i = a.length - 1; i > 0; i--) {
        var j = Math.floor(Math.random() * (i + 1));
        var temp = a[i];
        array[i] = a[j];
        a[j] = temp;
    }
    return a;
}

Example:

javascript
var array = ["car", "dog", "pony", "airplane"];
array = shuffleRandom(array);

Produces a random ordering of the array, for example: 

Array
(
    [0] => "dog"
    [1] => "pony"
    [2] => "car"
    [3] => "airplane"
)