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 ?
Asked
Active
Viewed 5,186 times
0

David
- 4,332
- 13
- 54
- 93
-
1`var arrTests = myString.split("/");` – Shadow The GPT Wizard Oct 11 '11 at 11:22
-
possible duplicate of [How do I split this string with JavaScript?](http://stackoverflow.com/questions/96428/how-do-i-split-this-string-with-javascript) – Sotiris Oct 11 '11 at 11:23
-
1-1 for terminal laziness. Did you not bother searching first? – Lightness Races in Orbit Oct 11 '11 at 12:18
-
-100 to you. Did you not bother read books only and not visit this site at all ? – David Oct 11 '11 at 12:57
5 Answers
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);

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