You can take the floating point number (between 0 and 1, non-inclusive) and convert it to an index to the array (integer between 0 and length of the array - 1). For example:

Copyvar a = ['a', 'b', 'c', 'd', 'e', 'f'];
var randomValue = a[Math.floor(a.length * Math.random())];
Answer from Lukáš Lalinský on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Math › random
Math.random() - JavaScript | MDN
The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range — which you can then scale to your desired range. The implementation selects the initial seed to the random ...
🌐
W3Schools
w3schools.com › js › js_random.asp
JavaScript Random
JSON Intro JSON Syntax JSON vs ... Interview Prep JS Bootcamp JS Certificate JS Reference ... Math.random() always returns a number lower than 1....
🌐
Programiz
programiz.com › javascript › examples › get-random-item
JavaScript Program to Get Random Item From an Array
A random number between 0 to array.length is generated using the Math.random() method.
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-array-exercise-35.php
JavaScript array: Get a random item from an array - w3resource
Write a JavaScript function that returns a random element from an array using Math.random() and floor.
🌐
Medium
medium.com › front-end-weekly › getting-a-random-item-from-an-array-43e7e18e8796
Playing with array in javascript using Math.random() | by Javascript Jeep🚙💨 | Frontend Weekly | Medium
November 12, 2019 - Let’s write a function to return a random element from an array. We can use Math.random() to generate a number between 0–1(inclusive of 0, but not 1) randomly.
🌐
W3Schools
w3schools.com › jsref › jsref_random.asp
JavaScript Math random() Method
The Math.random() method returns a random floating point number between 0 (inclusive) and 1 (exclusive).
🌐
TimOnWeb
timonweb.com › tim kamanin — a django/wagtail developer › javascript › how to get a random value from a javascript array
How to get a random value from a JavaScript array ⚡ | TimOnWeb
Math.floor(Math.random() * colors.length), gives us a random integer (array index) by rounding-down our normalized value to the nearest integer. Note that we don't use Math.ceil to round the number up because if we get something like 0.99 x ...
Find elsewhere
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › math › random integer array in range
Generate a JavaScript array of random integers in a given range - 30 seconds of code
March 15, 2024 - const randomIntArrayInRange = (min, max, n = 1) => Array.from( { length: n }, () => Math.floor(Math.random() * (max - min + 1)) + min ); randomIntArrayInRange(12, 35, 10); // [ 34, 14, 27, 17, 30, 27, 20, 26, 21, 14 ] ... Quickly and easily ...
🌐
Kirupa
kirupa.com › html5 › picking_random_item_from_array.htm
Picking a Random Item from an Array | kirupa.com
... To kick your array skills into ... right to it. The code for picking a random value from an array looks as follows: let randomValue = myArray[Math.floor(Math.random() * myArray.length)];...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-select-a-random-element-from-array-in-javascript
JavaScript - Select a Random Element from JS Array - GeeksforGeeks
How to select a random element from an array in JavaScript? The Math.random() method is used to get the random number between 0 to 1 (1 exclusive).
Published   July 12, 2025
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Math › random
JavaScript Math random() - Generate Random Number | Vultr Docs
November 29, 2024 - This function iteratively swaps each element with a randomly chosen element that has not been swapped yet, effectively shuffling the array. The Math.random() function in JavaScript is a versatile tool for generating random numbers and is ...
🌐
p5.js
p5js.org › reference › p5 › random
random
If the argument passed is a number, ... returns values between 0 and 5. If the argument passed is an array, random() returns a random element from that array....
🌐
YouTube
youtube.com › watch
Math Random and Arrays Random functions with JavaScript Code How to get Random Item from Array - YouTube
Learn JavaScript FREE Course - JavaScript How to create Dynamic and Interactive Web pages Math Random and Arrays Random functions with JavaScript Code How to...
Published   January 7, 2022
🌐
CoreUI
coreui.io › answers › how-to-generate-a-random-integer-in-javascript
How to generate a random integer in JavaScript · CoreUI
September 26, 2025 - For a range between two values, use the formula Math.floor(Math.random() * (max - min + 1)) + min. The second example generates integers from 1 to 10 inclusive. The + 1 ensures the maximum value is included in the possible results.
🌐
CSS-Tricks
css-tricks.com › snippets › javascript › select-random-item-array
Select Random Item from an Array | CSS-Tricks
December 23, 2016 - var myArray = [ "Apples", "Bananas", "Pears" ]; var randomItem = myArray[Math.floor(Math.random()*myArray.length)];