+ 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 Resposta
+ 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