Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

pick a random element from an array javascript

var myArray = [
  "Apples",
  "Bananas",
  "Pears"
];

var randomItem = myArray[Math.floor(Math.random()*myArray.length)];
Comment

Pick Random Value From Array

 javascriptCopyvar myArray = ['one', 'two', 'three', 'four', 'five'];
var rand = Math.floor(Math.random()*myArray.length);
var rValue = myArray[rand];
console.log(rValue)
Comment

get random item in array

function getRandomNumberElement(items: number[]): number {
    let randomIndex = Math.floor(Math.random() * items.length);
    return items[randomIndex];
}
Code language: TypeScript (typescript)
Comment

PREVIOUS NEXT
Code Example
Javascript :: jq get by name 
Javascript :: vehicle number regex 
Javascript :: react form on submit 
Javascript :: select first 3 letters js 
Javascript :: replace node 
Javascript :: javascript password max length 
Javascript :: server express node js 
Javascript :: input change event in javascript 
Javascript :: json-server 
Javascript :: multiple connections to mongoose 
Javascript :: javascript remove first space in string 
Javascript :: loopback find with limit 
Javascript :: node js get ip 
Javascript :: check overflow react 
Javascript :: react get current date yyyy-mm-dd 
Javascript :: react overflow scroll 
Javascript :: json schema string or null 
Javascript :: express.json 
Javascript :: window log scrollpostion 
Javascript :: angular router.navigate pass data 
Javascript :: p5.js add class to button 
Javascript :: react native run android 
Javascript :: javascript last element in array 
Javascript :: loopback model properties default 
Javascript :: javascript open new tab window 
Javascript :: express js server 
Javascript :: react image 
Javascript :: naming branches git 
Javascript :: subtract two date javascript 
Javascript :: javascript paragraph count 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =