0

I have such string test1/test2/test3/test4/test5 How can I get those tests in separate variables or in array or smth using javascript or jquery ?

David
  • 4,098
  • 13
  • 47
  • 87

5 Answers5

3
var arrayOfBits = string.split(separator)
dougajmcdonald
  • 18,151
  • 10
  • 52
  • 89
1

Use split
MN Documentation for split

var data = "test1/test2/test3/test4/test5".split("/");

Nick
  • 1,698
  • 14
  • 18
1

You could use split (so no jQuery required) -

var arr = "test1/test2/test3/test4/test5".split("/");
console.log(arr);

Demo http://jsfiddle.net/ipr101/hXLE7/

ipr101
  • 23,772
  • 7
  • 57
  • 61
1

You can use String.split(), where you specify the separator as "/" in the API, and get the array of values in return.

Saket
  • 44,171
  • 11
  • 57
  • 77
1

You can split a string by a delimiter.

https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/String/split

TJHeuvel
  • 11,944
  • 3
  • 36
  • 46