javascript - Move values from one array to another and remove them -


i have 20 number array. pick (randomly) 5 of these , wanna put them empty array. how can do? , also, how can hide them first array when they're displayed? thank all.

var tennumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 42, 178, 54, 76, 32, 12, 38, 154, 234]; var randomnumbers = document.getelementbyid("demo"); randomnumbers.innerhtml = tennumbers[math.floor(math.random()*tennumbers.length)]; 

seems should able use splice remove random element original array, push result onto new array:

var tennumbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 20, 42, 178, 54, 76, 32, 12, 38, 154, 234];  var outarray = [];  for(var i=0; i<5; i++) {      outarray.push(tennumbers.splice(math.floor(math.random()*tennumbers.length), 1)[0]);  }  document.write(outarray + "<br />" + tennumbers);


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -