js怎么随机生成汉字呢?
发布于 6 年前 作者 lovegnep 9558 次浏览 来自 问答

如下这种生成随机汉字的方式打印不出汉字。有没有其它办法?

let word = '\\u' +(Math.round(Math.random() * 20901) + 19968).toString(16);
console.log(word);
//打印
\u64d3
4 回复
String.fromCodePoint(Math.round(Math.random() * 20901) + 19968)
function decodeUnicode(str) {
   str = str.replace(/\\/g, "%");
   return unescape(str);
}

Unicode解码一下?

image.png 但是会有很多奇怪的字。

回到顶部