js get random number from array
//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 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);
Also in JavaScript:
- print array without brackets javascript
- js setinterval vs settimeout
- create-react-app redux
- how to search through a table javascript
- splice method js
- js obj getting count of properties
- javascript modal close
- javascript array remove last
- timestamp js
- js json stringfy beutify
- document.querySelector
- javascript remove element from array
- if odd js
- or operator js
- localecompare javascript
- react import brackets
- javascript arrow function
- javascript span style
- js output html
- get object with max value javascript
- split array by character javascript
- jsdoc optional param
- how to pass callback function in javascript
- concise body arrow functions javascript