1// Split string into an array of strings
2const path = "/usr/home/chucknorris"
3let result = path.split("/")
4console.log(result)
5// result
6// ["", "usr", "home", "chucknorris"]
7let username = result[3]
8console.log(username)
9// username
10// "chucknorris"
1// bad example https://stackoverflow.com/questions/6484670/how-do-i-split-a-string-into-an-array-of-characters/38901550#38901550
2
3var arr = foo.split('');
4console.log(arr); // ["s", "o", "m", "e", "s", "t", "r", "i", "n", "g"]
1// Example array.
2let randomArray = [3, 5, 1, 5, 7,];
3// Create an empty array.
4let arrayOfArrays = [];
5
6function splitArray( array ) {
7 while (array.length > 0) {
8 let arrayElement = array.splice(0,1);
9 arrayOfArrays.push(arrayElement);
10 }
11 return arrayOfArrays;
12}
13
14// Call the function while passing in an array of your choice.
15splitArray(randomArray)
16// => [ [ 3 ], [ 5 ], [ 1 ], [ 5 ], [ 7 ] ]
1var str = "12,15,16,78,59";
2var res = str.split(",");
3console.log(res[0]); // result: 12
4console.log(res[2]); // result: 16
1var input = 'john smith~123 Street~Apt 4~New York~NY~12345';
2
3var fields = input.split('~');
4
5var name = fields[0];
6var street = fields[1];