function formatName(name) {
let newStr;
if (name.length === 2) {
newStr = name.substr(0, 1) + '*';
} else if (name.length > 2) {
let char = '';
for (let i = 0, len = name.length - 2; i < len; i++) {
char += '*';
}
newStr = name.substr(0, 1) + char + name.substr(-1, 1);
} else {
newStr = name;
}
return newStr;
}
js改变评论者中间部分名字为星号
最新推荐文章于 2022-05-11 15:57:14 发布