str.random()
random character in string
๐ฐ JS โฉ Types โฉ String โฉ methods
// โญ๏ธ 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
Was this helpful?