“Numer wyciągu JavaScript z ciągu” Kod odpowiedzi

JS wyodrębnia tylko liczby z ciągów

"1.23-45/6$7.8,9".replace(/[^0-9]/g,'')

// Response: "123456789"
Tarik

JS otrzymuje numer z ciągów

 thenum = "foo3bar5".match(/\d+/)[0] // "3"
Borma

Uzyskaj numer z String JavaScript

str = "hello123!"	
str.match(/(\d+)/)[1]	//Best way to find first matching number in string ;)
Armandres

Numer wyodrębnia z String JavaScripy

function justNumbers(string) {
  var numsStr = string.replace(/[^0-9]/g, '');
  return parseInt(numsStr);
}

var input = "Rs. 6,67,000";
var number = justNumbers(input);
console.log(number); // 667000
 Run code snippet
Inquisitive Impala

JavaScript Znajdź cyfrę w Str

var regex = /\d+/g;
var string = "Any string you want!";
var matches = string.match(regex);  // creates array from matches

if (matches){
  // There is a digit in the string.
} else {
  // No Digits found in the string.
}
Vivacious Vendace

Numer wyciągu JavaScript z ciągu


// Html: <span id="foo">280ms</span>

var text = $('#foo').text();
var number = parseInt(text, 10);
alert(number);

// parseInt('ms120'.replace(/[^0-9\.]/g, ''), 10);
Agreeable Angelfish

Odpowiedzi podobne do “Numer wyciągu JavaScript z ciągu”

Pytania podobne do “Numer wyciągu JavaScript z ciągu”

Więcej pokrewnych odpowiedzi na “Numer wyciągu JavaScript z ciągu” w JavaScript

Przeglądaj popularne odpowiedzi na kod według języka

Przeglądaj inne języki kodu