javascript - how to count character occurrences in a string using javascript [ with source code ]

javascript - how to count character occurrences in a string using javascript [ with source code ]

1BestCsharp blog

6 лет назад

19,627 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Rushi Sawant
Rushi Sawant - 09.06.2021 11:43

Nothing a useful information in this video

Ответить
ugh
ugh - 30.01.2020 18:36

what if I wanted to count all the c's & r's? for example: let count_me = "cr"...

Ответить
Dániel Palágyi
Dániel Palágyi - 08.03.2019 07:32

some explanation wouldn't have hurt anybody..

Ответить
Claudio Bereber
Claudio Bereber - 01.10.2018 15:38

<!DOCTYPE html>
<html>
<body>
<form>
INPUT TEXT <input type = "text" id = "textbox1">
<br> <br>
Count <input type = "text" id = "textbox2">
<br><br>
TOTAL <input type = "text" id = "total">
<br><br>
<button type = "button" onclick = "gettext()"> bobo</button>
</form>
<script>
function gettext(){
var txt = document.getElementById("textbox1"),
count = 0;

for (var i = 0; i<txt.length; i++){
if(txt.charAt(i) === document.getElementById("textbox2")){
count++;
}
}
document.getElementById("total").value = count;
}
</script>

</body>
</html>

the output is 0 what do I do

Ответить