str.random()

random character in string

🔰 JSTypesStringmethods

// ⭐️ string.random()
// ⭐️ Note: this may not work well with Unicode❗️ 
String.prototype.random = function(){
    return this[randomInt(this.length)];
}

// ⭐️ randomChar(str)
// ⭐️ Note: this may not work well with Unicode❗️
export function randomChar(str) {
    return str[randomInt(0, str.length - 1)];
}

Last updated