pick random string from array javascript
var items = ['Yes', 'No', 'Maybe'];
var item = items[Math.floor(Math.random() * items.length)];var myArray = [
"Apples",
"Bananas",
"Pears"
];
var randomItem = myArray[Math.floor(Math.random()*myArray.length)];var groceries = [
'milk',
'coriander',
'cucumber',
'eggplant'
]
let mygroceries = groceries[Math.floor(Math.random() * groceries.length)]
console.log(mygroceries)//This gives you any string from groceries
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
const randomMonth = months[Math.floor(Math.random() * months.length)];
console.log("random month =>", randomMonth);const randomElement = array[Math.floor(Math.random() * array.length)];
Also in JavaScript:
- if between two numbers javascript
- react native text wrap
- javascript shuffle array
- node code comment process real time
- get every other item in an array
- promise in javascript
- how to use jq with json data
- pi in js
- active-class router-link
- javascript .slice() function
- axios Cross origin http://localhost forbidden
- checkbox is checked jquery
- phaser game height
- local storage javascript object
- web scraping nodejs
- get keys objet javascript
- how to recognize an array in javascript
- keydown shift tab angular
- javascript pagination demo
- difference between == and === in javascript
- build an api in nodejs using express to send emails using the gmail rest api without client libraries
- javascript substring after character
- javascript parse to string
- react native docs