how to select a random element from an object in javascript code example
Example 1: js get random number from array
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);
Example 2: get random elements from array javascript
array.sort(() => Math.random() - Math.random()).slice(0, n)