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