'123xswer'
How to retrieve 123 from the string above without using regular expression?
'123xswer'
How to retrieve 123 from the string above without using regular expression?
Use split
function .
var str='123xwer' ;
arr = str.split('x') ;
alert ( arr[0] ) ;
> parseInt('123xswer', 10)
123
(Leading zeros won't be kept.)
(The "10" is to specify we want decimal numbers, so that 099abcd
can return the expected integer.)