Select a quote from a list randomly
Random item from array

You don't need the for loop to select a random item from an array.

Just get an index using Math.floor(Math.random() * array.length)

function getRandomQuote(array) {
    return array[Math.floor(Math.random() * array.length)];
}


Or as an arrow function, and you don't need the get part of the function name that is implied.

const randomQuote = array =&gt; array[Math.floor(Math.random() * array.length)];


You can also use bitwise or zero | 0 in place of the Math.floor function

const randomQuote = array =&gt; array[Math.random() * array.length | 0];


Random pick from array

If you wish to ensure each quote is randomly selected and not repeating until all have been randomly selected you can create a copy of the array, and pick items from that using Array.splice until empty, then copy the source array again.

For example the function encapsulates array and source You must first call the function with an array, then any other calls will return a random item that does not repeat until all items have been picked.

const randomQuote = (() =&gt; {
    const picked = []; // to hold picked items
    var source;   // array of items to pick from 
    return srcArray =&gt; {
        if (srcArray) {
            source = srcArray;
            picked.length = 0;
        } else {
            if (!picked.length) { picked.push(...source) }
            return picked.splice(Math.random() * picked.length | 0, 1)[0];
        }
    }
})();

randomQuote(["a","b","c","d","e","f"]); // set up the source array
console.log(randomQuote()); // display random quote in console.


At any time you can reset the source array by calling the function with an array.

Random and the array, common functions

Here is a set of common functions that use random to access arrays. Rather than have functions rely on each other, each function is written to be entirely stand alone. If you use many of them it will pay to encapsulate them all in an object.

const randItem = arr =&gt; arr[Math.random() * arr.length | 0];
const randPick = arr =&gt; arr.splice(Math.random() * arr.length | 0, 1)[0];
const randPut = (arr, item) =&gt; arr.splice(Math.random() * (arr.length + 1) | 0, 0, item);
const randShuffle = arr =&gt; { 
    var len = arr.length
    while (len) { 
        arr.push(arr.splice(Math.random() * (len--) | 0, 1)[0]); 
    }
    return arr;
}   
const randPlay = (arr, repeat) {
    var item;
    repeat = repeat &gt; arr.length ? arr.length : repeat
    arr.push(item = arr.splice(Math.random() * repeat | 0, 1)[0]);
    return item;
}


What they do.   


randItem(array)  return a random item but does not remove it
randPick(array)  returns a random item removing it from the array
randPut(array, item) randomly inserts the item into the array
randShuffle(array) Shuffles the array in place (does not make a copy)
randPlay(array, number) A variation on the no repeat, selects random items from the bottom number items. Good for play lists when you dont want to repeat the same track. Use with randShuffle on the array before you call randPlay. The same item will not play again until another array.length - number items have played.