Quick actions

cmd+k|ctrl+k

Navigation

Languages

Choosing Random Item in Array

Snippet info

Language

JavaScript

Visibility

public

Author

damoe4

Created

2017-06-07T15:11:06Z

Updated

2017-06-07T15:11:06Z

var commonWords = [
  "the","of","and","a","to","in","is","you","that","it","he",
  "was","for","on","are","as","with","his","they","I","at","be",
  "this","have","from","or","one","had","by","word","but","not",
  "what","all","were","we","when","your","can","said","there",
  "use","an","each","which","she","do","how","their","if","will",
  "up","other","about","out","many","then","them","these","so",
  "some","her","would","make","like","him","into","time","has",
  "look","two","more","write","go","see","number","no","way",
  "could","people","my","than","first","water","been","call",
  "who","oil","its","now","find","long","down","day","did","get",
  "come","made","may","part"
];

// Create a function that choses a random word from `commonWords` and returns it
var chooseRandomWord = function(array) {
  var index = Math.floor((Math.random() * array.length))
 return array[index]
}
 console.log(chooseRandomWord(commonWords))
 
 
 
INFO