Example: Get Random Item From an Array
Output
'hello'
In the above program, a random item from an array is accessed.
- A random number between 0 to array.length is generated using the
Math.random()method. - The
Math.floor()returns the nearest integer value generated byMath.random(). - This random index is then used to access a random array element.