Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Get a Random Item from an Array</title> </head> <body> <script> // Sample array var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]; // Getting a random value var randomItem = days[Math.floor(Math.random() * days.length)]; document.write(randomItem); </script> </body> </html>