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,332
  • 13
  • 54
  • 93

5 Answers5

3
var arrayOfBits = string.split(separator)
dougajmcdonald
  • 19,231
  • 12
  • 56
  • 89
1

Use split
MN Documentation for split

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

Nick
  • 1,708
  • 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
  • 24,096
  • 8
  • 59
  • 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
  • 45,521
  • 12
  • 59
  • 79
1

You can split a string by a delimiter.

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

TJHeuvel
  • 12,403
  • 4
  • 37
  • 46