Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
输入字段中的第一个字母显示,其余字母不可见,如******如何在javascript和typescript中执行?_Javascript_Typescript - Fatal编程技术网

输入字段中的第一个字母显示,其余字母不可见,如******如何在javascript和typescript中执行?

输入字段中的第一个字母显示,其余字母不可见,如******如何在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 -

用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 - 1);
console.log(res);
它将获得单词的第一个字符,并将原始单词减去第一个字符的长度加*倍

编辑:

是否应该是
word[0]
?我知道OP有类似的代码,但它应该是h****在我的理解中,最初我是用
word[0]
做的,但后来意识到OP有
word[1]
所以我改变了它