//字符串首字母大写
const capitalize = (str) => str.charAt(0).toUpperCase() + str.slice(1);
//2. 翻转字符串
const reverse = (str) => str.split("").reverse().join("");
//随机字符串
const randomString = () => Math.random().toString(36).slice(2);
//截断字符串
const truncateString = (string, length) =>
string.length < length ? string : `${string.slice(0, length - 3)}...`;
//去除字符串中的HTML
const stripHtml = (html) =>
new DOMParser().parseFromString(html, "text/html").body.textContent ||
"";
},
字符串处理:1字符串首字母大写 2翻转字符串 3随机字符串 4截断字符串 5去除字符串中的HTML
最新推荐文章于 2024-09-04 11:56:14 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)