输入字段中的第一个字母显示,其余字母不可见,如******如何在javascript和typescript中执行?
用Python输入字段中的第一个字母显示,其余字母不可见,如******如何在javascript和typescript中执行?,javascript,typescript,Javascript,Typescript,用Python word = 'hello' word[1] + '*' * len(word[1:]) 输出为“e****”您可以这样做,使用: const word='hello'; const res=word[1]+'*'.重复(word.length-1); 控制台日志(res)您可以通过运行以下代码来实现: const word = "foo"; const res = word[0] + "*".repeat(word.length -
word = 'hello'
word[1] + '*' * len(word[1:])
输出为“e****”您可以这样做,使用:
const word='hello';
const res=word[1]+'*'.重复(word.length-1);
控制台日志(res)代码>您可以通过运行以下代码来实现:
const word = "foo";
const res = word[0] + "*".repeat(word.length - 1);
console.log(res);
它将获得单词的第一个字符,并将原始单词减去第一个字符的长度加*倍
编辑:
是否应该是word[0]
?我知道OP有类似的代码,但它应该是h****在我的理解中,最初我是用word[0]
做的,但后来意识到OP有word[1]
所以我改变了它