$1.45

How to get random values from a JavaScript array?

Ask a question+
1

How can I get values randomly from this array in the sample below?

var myArray = ['January', 'February', 'March'];
BabkenM 970
add comment

1 Answer

0

I hope this help you

function random_item(myArray)
{
    return myArray[Math.floor(Math.random()*myArray.length)];
}

var myArray = ['January', 'February', 'March'];
console.log(random_item(myArray));
Ruben 80
add comment

Your Answer