Liam Shackhorn
Liam Shackhorn

Reputation: 25

Split a string into two variables using NodeJS

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

Answers (1)

Nina Scholz
Nina Scholz

Reputation: 386560

You could split the string and take a destructuring assignment.

var [o, n] = 'Supporter->VIP'.split('->');

console.log(o, n);

Upvotes: 4

Related Questions