get random element from array js
//get random value from array
var colors = ["red","blue","green","yellow"];
var randColor = colors[Math.floor(Math.random() * colors.length)];
var myArray = [
"Apples",
"Bananas",
"Pears"
];
var randomItem = myArray[Math.floor(Math.random()*myArray.length)];const randomElement = array[Math.floor(Math.random() * array.length)];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);var item = items[Math.floor(Math.random() * items.length)];
Also in JavaScript:
- remove backslash in json array javascript
- jquery parsexml get attribute
- js escape url parameter
- swap scroll right in react native
- ejs / javascript check if array/object exists and is not empty
- extension for local storage in angular 8
- how to implement a promise with daisy chaining in angular
- unix time to date javascript
- js detect all images errors
- settimeout in loop javascript
- jquery ajax json
- most used events in javascript
- sort array based on another array
- postfix date javascript
- how to change package name in react native
- global scope js
- getelementbyclass
- node js event emitter
- vscode entenstion build
- js isset
- javascript move array element to front
- javaascript all
- momentjs docs
- jquery get request