1
2// Html: <span id="foo">280ms</span>
3
4var text = $('#foo').text();
5var number = parseInt(text, 10);
6alert(number);
7
8// parseInt('ms120'.replace(/[^0-9\.]/g, ''), 10);
1str = "hello123!"
2str.match(/(\d+)/)[1] //Best way to find first matching number in string ;)
1var regex = /\d+/g;
2var string = "Any string you want!";
3var matches = string.match(regex); // creates array from matches
4
5if (matches){
6 // There is a digit in the string.
7} else {
8 // No Digits found in the string.
9}
1const num = 123; //> type number 123
2const str = num.toString(); //> type string "123"