You should use map
and sort
methods.
First of all, you can generate a random number for every item in the array, using Math.random
method. Next step is to sort array by this generated
number.
Last step is to create the sentence with the items of the array, using join
method.
var array1 = ["The", "Man", "and", "his", "dog"];
console.log(array1.map(function(n){
return [Math.random(), n];
}).sort().map(function(item){
return item[1] ;
}).join(' '));