How to get integer 40 from the text "his age is 40"? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 1

How to get integer 40 from the text "his age is 40"?

I tried the parseInt() method but it is returning NaN. Is there anyother way to get that integer?

9th May 2020, 9:42 PM
Hassan Raza
Hassan Raza - avatar
1 Réponse
+ 5
Using regex. let text = "His age is 40"; let age = parseInt(text.match(/\d+/g, text)); console.log(age); //40
9th May 2020, 9:51 PM
Russ
Russ - avatar