1
let string = "13th" string = Number(string) 

I expect it to return 13 instead I get NaN please how do I go about it

0

1 Answer 1

7

Try with parseInt()

If parseInt encounters a character that is not a numeral in the specified radix, it ignores it and all succeeding characters and returns the integer value parsed up to that point. parseInt truncates numbers to integer values. Leading and trailing spaces are allowed.

let string = "13th"; string = parseInt(string); console.log(string);

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.