Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,089 questions

40,774 answers

573 users

What is the isdigit() equivalent in JavaScript

3 Answers

0 votes
function isdigit(ch) {
    return ch >= '0' && ch <= '9';
}
 
const s = "c23c++45javascript23988rust98";
const size = s.length;
     
for (let i = 0; i < size; i++) {
     if (isdigit(s.charAt(i))) {
         console.log(s.charAt(i));
      }
}
 
 
 
 
 
 
/*
run:
 
"2"
"3"
"4"
"5"
"2"
"3"
"9"
"8"
"8"
"9"
"8"
 
*/

 





answered Jun 2, 2023 by avibootz
edited Jun 2, 2023 by avibootz
0 votes
function isdigit(ch) {
   return /^\d+$/.test(ch);
}

const s = "c23c++45javascript23988rust98";
const size = s.length;
    
for (let i = 0; i < size; i++) {
     if (isdigit(s.charAt(i))) {
         console.log(s.charAt(i));
      }
}






/*
run:

"2"
"3"
"4"
"5"
"2"
"3"
"9"
"8"
"8"
"9"
"8"

*/

 





answered Jun 2, 2023 by avibootz
0 votes
function isdigit(ch) {
   return  !isNaN(parseFloat(ch));
}



const s = "c23c++45javascript203988rust98";
const size = s.length;
    
for (let i = 0; i < size; i++) {
     if (isdigit(s.charAt(i))) {
         console.log(s.charAt(i));
      }
}






/*
run:

"2"
"3"
"4"
"5"
"2"
"0"
"3"
"9"
"8"
"8"
"9"
"8"

*/

 





answered Jun 2, 2023 by avibootz

Related questions

1 answer 30 views
1 answer 60 views
60 views asked Aug 7, 2021 by avibootz
2 answers 55 views
1 answer 181 views
...