Extract a number from a string (JavaScript)

前端 未结 22 1674
灰色年华
灰色年华 2020-11-22 06:38

I have a string in JavaScript like #box2 and I just want the 2 from it.

I tried:

var thestring = $(this).attr(\'href\');
var          


        
22条回答
  •  不要未来只要你来
    2020-11-22 07:10

    You should try the following:

    var txt = "#div-name-1234-characteristic:561613213213";
    var numb = txt.match(/\d/g);
    numb = numb.join("");
    alert (numb);​
    

    result

    1234561613213213
    

提交回复
热议问题