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*/
1var myString = "An,array,in,a,string,separated,by,a,comma";
2var myArray = myString.split(",");
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// Split a string into an array of substrings:
2var String = "Hello World";
3var Array = String.split(" ");
4console.log(Array);
5//Console:
6//["Hello", "World"]
7
8///*The split() method is used to split a string into an array of substrings, and returns the new array.*/