💾arr.randomElement
random element in array (undefined if array is empty)
Last updated
Was this helpful?
random element in array (undefined if array is empty)
Last updated
Was this helpful?
Was this helpful?
require: randomInt()
// ⭐️ arr.randomElement
Object.defineProperty(Array.prototype, 'randomElement', {
get() { return this[randomInt(this.length)] }
});
// ⭐️ randomElement(arr)
function randomElement(arr){
return arr[randomInt(arr.length)];
}