1

If I have the following:

(8

Is there a way to get the number 8 out of it without splitting it? Using parseInt returns NaN. Is there an alternative to parseInt that ignores non-numbers?

1

2 Answers 2

7
parseInt(str.replace(/[^\d]/g, ''), 10)
Sign up to request clarification or add additional context in comments.

Comments

3

You can use a quick regex to match that number, and just prepend + to cast to number:

var num =+ '(8'.match(/\d+/)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.