We're a place where coders share, stay up-to-date and grow their careers.
It is using Math.random, just added sugar around it. Made a ton prototypes long time ago for such tasks
Array.prototype.getRandom = function () { return this[Math.floor(Math.random() * this.length)]; }; console.log( [1, 2, 3].getRandom() )
It is using Math.random, just added sugar around it.
Made a ton prototypes long time ago for such tasks