-1

How can I extract numeric part from value stored in another variable ?

For example:

 var a=some_string ;

Now I want to extract numeric value of a and store it in another variable .

3
  • 1
    how does your some_string look like. you could probably use parseInt developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/…. Again it depends on the format of your string Commented Nov 12, 2014 at 9:58
  • @unikorn My string is "submit1" and it changes every time Commented Nov 12, 2014 at 10:02
  • changes to what? does the format remain the same. for e.g submit1 to submit3? Commented Nov 12, 2014 at 10:05

1 Answer 1

1

Example--

var a='kjh56SS';
var b='';
for(var i=0;i<a.length;i++){
    if(!isNaN(a.charAt(i))){
         b=b+a.charAt(i);
    }
}
alert(b);

Demo-- http://jsfiddle.net/mwkn4c8t/

Sign up to request clarification or add additional context in comments.

1 Comment

Solution looks dumb and inefficient without regex !! You can go for regex answers if you want!!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.