Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to get random value less than in array js

var items = [1, 2, 3, 4, 5];
var newItems = [];

for (var i = 0; i < 1; i++) {
  var idx = Math.floor(Math.random() * items.length);
  newItems.push(items[idx]);
  items.splice(idx, 1);
}

console.log(newItems);
 Run code snippetHide results
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #random #array #js
ADD COMMENT
Topic
Name
4+3 =