Say I had
var imgs = ["pItem1","pItem2","pItem3","pItem4","pItem5"]
How can get a new array from the current one, that randomly picks lets say 3 items from the old array and puts it in a new array.
var newArray =["pItem1," "pItem4," "pItem2"];
Say I had
var imgs = ["pItem1","pItem2","pItem3","pItem4","pItem5"]
How can get a new array from the current one, that randomly picks lets say 3 items from the old array and puts it in a new array.
var newArray =["pItem1," "pItem4," "pItem2"];
You're basically looking to take a randomly sampled subset of an array. One approach is to randomly shuffle the array, then take a slice from the beginning of the array. See this implementation of getRandomSubarray()
in another answer: https://stackoverflow.com/a/11935263/2943575