Q:

How to select single Integer value from a String?

So I have a string X = '03456789'
And another string Y = '12809009'
If the first two integers in my variable are 03 like in X, I want to be able to store them as a single value (3) .. and if first two integers are like 12, I want to store them as (12). How can I achieve that in Javascript.

A:

One way to do this:
+X.slice(0,2)

In javascript a string is an array of characters. So you use the slice function to select the first two elements. The + sign will convert the resulting string to a number.

