1//split into array of strings.
2var str = "Well, how, are , we , doing, today";
3var res = str.split(",");
1var myString = "An,array,in,a,string,separated,by,a,comma";
2var myArray = myString.split(",");
3/*
4*
5* myArray :
6* ['An', 'array', 'in', 'a', 'string', 'separated', 'by', 'a', 'comma']
7*
8*/
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"]
1let countWords = function(sentence){
2 return sentence.split(' ').length;
3}
4
5console.log(countWords('Type any sentence here'));
6
7//result will be '4'(for words in the sentence)
1// It essentially SPLITS the sentence inserted in the required argument
2// into an array of words that make up the sentence.
3
4var input = "How are you doing today?";
5var result = input.split(" "); // Code piece by ZioTino
6
7// the following code would return as
8// string["How", "are", "you", "doing", "todaY"];