Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript select random element from array

let fruits = ["Apple", "Banana", "Mango", "Orange"]; // array
let index = Math.floor(Math.random() * fruits.length); // random index
console.log(fruits[index]); // result
Comment

select a random element from from items array

var item = items[Math.floor(Math.random()*items.length)];
Comment

PREVIOUS NEXT
Code Example
Javascript :: react media query hook 
Javascript :: jquery read href attribute 
Javascript :: give multiple classes in modular css react 
Javascript :: nodejs express return image 
Javascript :: add color to console 
Javascript :: disable unused vars 
Javascript :: cancel settimeout 
Javascript :: javascript truncate string full word 
Javascript :: ng build staging 
Javascript :: javascript average function 
Javascript :: react native apk build 
Javascript :: set a previous year to the current date in javascript 
Javascript :: extract number from string 
Javascript :: react native open phone 
Javascript :: (node:2496) DeprecationWarning: collection.ensureIndex is deprecated. Use createIndexes instead. 
Javascript :: javascript date minus minutes 
Javascript :: Exceeded timeout of 5000 ms for a test. Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test." 
Javascript :: have flat list automatically wrap react native 
Javascript :: how to get current date in js 
Javascript :: remove text javascript 
Javascript :: sequelize limit 
Javascript :: refresh event in javascript 
Javascript :: javascript in line logic 
Javascript :: split a message js 
Javascript :: check if a variable is a number in javascript 
Javascript :: link to another page and achor 
Javascript :: how to use sweet alert in vue js 
Javascript :: export variables react 
Javascript :: how to get timestamp in javascript of a date object 
Javascript :: change value of key in array of objects javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =