JavaScript, randomly pick a number from an array

I am about to transfer my blog to my own domain; however, the WordPress over there cannot detect the newest version of WordPress yet, which it’s annoying. After it’s successfully upgraded, I will transfer my blog there.

Well, before I do so, I would like to clip a method which I found online.

var items = [1,2,3,4,5];
var randomPick = items[Math.floor(Math.random()*items.length)];
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s