/    Sign up×
Community /Pin to ProfileBookmark

splitting up a value into multiple variables

Hello,
How would I take a value, for instance: 85 and convert each digit into a variable. (Like digit1 and digit2). But before it converts it, it checks to see if there are one or two digits, if one: the variable digit1 would equal zero and then digit2 would be the value.
Any help is appreciated!

Thanks,
Steve

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@balloonbuffoonauthorFeb 27.2005 — Thanks to anyone who looked at this, but I figured it out.

I just had to use javascript's split() function.

For instince:
<i>
</i>var myvalue = "85";
var digits = myvalue.split("");

then I would get an array:

digits[0] would be "8"

and

digits[1] would be "5"

-Steve
Copy linkTweet thisAlerts:
@ExuroFeb 27.2005 — You could also use the [FONT=courier new]charAt()[/FONT] method of the string:
[code=php]var myStr = "85";
alert(myStr.charAt(0)); // Displays "8"
alert(myStr.charAt(1)); // Displays "5"[/code]
Copy linkTweet thisAlerts:
@balloonbuffoonauthorFeb 27.2005 — That's a good idea for if I needed two differently named variables, thanks for the tip.

-Steve
Copy linkTweet thisAlerts:
@herodote92Feb 27.2005 — Oh, I never thought of using String.split(""), but actually, this is interesting. I just found in my reference book that the opposite method would be Array.join().

Eh eh, one learns a little bit every day...

?
×

Success!

Help @balloonbuffoon spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...