+ 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?
1 Respuesta
+ 5
Using regex.
let text = "His age is 40";
let age = parseInt(text.match(/\d+/g, text));
console.log(age); //40