-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?

gespinha
  • 7,968
  • 16
  • 57
  • 91
  • While you received several answers already, this is really a thing you should have been able to find with a simple web search, as explained in ["how to ask questions on Stackoverflow"](http://stackoverflow.com/help/how-to-ask) – Mike 'Pomax' Kamermans Jun 05 '15 at 17:16
  • You really couldn't search for [`[javascript] string to array`](http://stackoverflow.com/search?q=%5Bjavascript%5D+string+to+array)? – Felix Kling Jun 05 '15 at 17:17

2 Answers2

2

Use split() like

var group = "one+two+three";
var groupArray = group.split('+');
console.log(groupArray);
AmmarCSE
  • 30,079
  • 5
  • 45
  • 53
1

You can simply split() it:

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

Try

Dhaval Marthak
  • 17,246
  • 6
  • 46
  • 68