Jtaylorapps
Jtaylorapps

Reputation: 5780

Split Apart Formatted Numbers & Assign As Variables

Using Titanium IDE, in JavaScript. I think this is going to have to happen using Regex, as well.

So, I'm trying to take something like 5-6-7 and split it up so that, for example, I take the first number (in this case, 5), and then bring that into a variable to use later on. This would be the same for all the numbers, so that I end up with something like var one = 5; var two = 6; var three = 7;

That way, I'd be able to take specific digits and use their values instead of taking it as a whole.

I've been working on this for about two hours now, but since my understanding of Regex or other similar text formatting) is pretty bad at this point (learning!), I could use the extra help. Thanks!

Upvotes: 0

Views: 48

Answers (1)

Aaria Carter-Weir
Aaria Carter-Weir

Reputation: 1679

I'm pretty sure you can access the data like this:

var list = "1-6-7-123-123-3-21-3",
    items = list.split('-');

console.log(items[1]); // logs "6"
console.log(items[0]); // logs "1"
console.log(items[3]); // logs "123"

Upvotes: 1

Related Questions