const list = [1, 2, 3, 4, 5, 6];
// shuffle your list with the sort function:
const shuffledList = list.sort(() => Math.random() - 0.5);
// generate a size for the new list
const newListSize = Math.floor(Math.random() * list.length)
// pick the first "newListSize" elements from "shuffledList"
const newList = shuffledList.slice(0, newListSize)
console.log(newList);
// [3, 2, 6]; [5]; [4, 1, 2, 6, 3, 5]; []; etc..
//Make all arrays have "random" method
Array.prototype.random = function() {
return this[Math.floor(Math.random() * this.length)];
}
//Call "random" method on an array
var result = ["Hello", "world"].random();