Reputation: 25
I'm trying to figure out how to split a string into two parts like
Supporter->VIP
in NodeJS. For example:
var Old = Supporter
var New = VIP
Would I have to use .split()
somehow? Or is there a way I can use a RegExp? The ->
would always be in between the two.
Sorry I couldn't be more descriptive. I'm a bit lost.
Upvotes: 1
Views: 545
Reputation: 386560
You could split the string and take a destructuring assignment.
var [o, n] = 'Supporter->VIP'.split('->');
console.log(o, n);
Upvotes: 4