From a given array arr, a random return of num not duplicates
function getarrayitems (arr, num) {
///Create an array, copy the incoming array for operation, not directly manipulate the incoming array;
var temp_array = new Array ();
For (var index in arr) {
temp_array.push (Arr[index]);
}
The value of the item to be removed, saved in this array
var return_array = new Array ();
for (var i = 0; i<num; i++) {
//judge if the array also has the elements that can be taken out, in case the subscript crosses
over if (temp_array.length>0) {
///generates a random index in the array C13/>var Arrindex = Math.floor (Math.random () *temp_array.length);
Copy the corresponding array element value of this random index
return_array[i] = Temp_array[arrindex];
Then the array element of this index is deleted, at which point the Temp_array becomes the new array
temp_array.splice (Arrindex, 1), or
else {
//The data entry in the array exits the loop For example, the array originally had only 10 items, but required 20 items to be removed.
break;
}
}
return return_array;
}
Test
var arrlist=[ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33];
Alert (Getarrayitems (arrlist,6));