Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript sample list

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..
Comment

PREVIOUS NEXT
Code Example
Javascript :: html string to object jquery 
Javascript :: js tab active 
Javascript :: how to get the first letter of a string in jquery 
Javascript :: factorial function javascript 
Javascript :: js send get method 
Javascript :: redux saga delay 
Javascript :: transitionduration js 
Javascript :: close tab using jquery 
Javascript :: react native elevation 
Javascript :: random integer in nodejs 
Javascript :: javascript create array from 1 to n 
Javascript :: replace comma by new line in js 
Javascript :: how to get time and date from iso string javascript 
Javascript :: store id of an element jquery 
Javascript :: material ui align icon with text 
Javascript :: express serve home page 
Javascript :: javascript colorized console.log 
Javascript :: generate random whole number between 2 javascript 
Javascript :: scroll to section react 
Javascript :: pauze js 
Javascript :: regex any character 
Javascript :: zoom out browser javascript 
Javascript :: difference between == and === in javascript 
Javascript :: read json from file js 
Javascript :: install react native gifted charts 
Javascript :: adb bootloader reboot 
Javascript :: how to check if div is display none jquery 
Javascript :: lodash remove undefined values from object 
Javascript :: add image in react native 
Javascript :: compare two arrays and make sure there are no duplicates js 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =