-1

I have the following string:

var group = "one+two+three";

Each value in the string is separated by a +, and I wanted to add them separately in an array, so It could then become:

var group_array = ["one", "two", "three"];

How can I do this?

2

2 Answers 2

2

Use split() like

var group = "one+two+three";
var groupArray = group.split('+');
console.log(groupArray);

Sign up to request clarification or add additional context in comments.

Comments

1

You can simply split() it:

var groupArray = "one+two+three".split("+");
// -> will give you ["one", "two", "three"];

Try

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.