jadjoubran / codetogo.io

🚀 JavaScript code to go - Find updated snippets for common JavaScript use cases
https://codetogo.io
MIT License
233 stars 30 forks source link

Use Case Suggestion: sample from array #249

Closed dwiehoff closed 4 years ago

dwiehoff commented 4 years ago
var array = [
  "Apples",
  "Bananas",
  "Pears"
];

var randomItem = array[ Math.floor(Math.random() * array.length) ];
jadjoubran commented 4 years ago

Hey @dwiehoff This already exists here: How to get random element from array in JavaScript