How to extract number from a string in javascript

前端 未结 9 704
清歌不尽
清歌不尽 2020-12-08 19:23

I have an element in javascript like follows:

 280ms

I want to extract 280 from the span element. How can I do it?

9条回答
  •  再見小時候
    2020-12-08 20:03

    Try the following

    var strValue = // get 280m from the span
    var intValue = parseInt(strValue.match(/[0-9]+/)[0], 10);
    

提交回复
热议问题