How to replace String with a number in JavaScript

Asked 2 years ago, Updated 2 years ago, 17 views

I just want to get a number from the string "Hello, I'm 24 years old" in JavaScript How can you do that?

javascript

2022-09-22 22:08

1 Answers

You can import it using a regular expression.

var str = "Hi, I'm 24 years old";
var num = str.replace(/[^0-9]/g,"");

You can do it like this.


2022-09-22 22:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.