Q:

js .split

// bad example https://stackoverflow.com/questions/6484670/how-do-i-split-a-string-into-an-array-of-characters/38901550#38901550

var arr = foo.split(''); 
console.log(arr); // ["s", "o", "m", "e", "s", "t", "r", "i", "n", "g"]
16
var input = "How are you doing today?";
var result = input.split(" ");

// result is string[] {"How", "are", "you", "doing", "today?"}
16

var str = "How are you doing today?";

var res = str.split(" ");
 
7
	var string = "This is an interesting sentence.";
	var response = str.split(" ");
	console.log(response)
	/* Expected result:
    This,is,an,interesting,sentence.
    (Note: returns array)
    */
12
var str = "12,15,16,78,59";
var res = str.split(",");
console.log(res[0]); // result: 12
console.log(res[2]); // result: 16
0
let countWords = function(sentence){
    return sentence.split(' ').length;
}

console.log(countWords('Type any sentence here'));

//result will be '4'(for words in the sentence)
5
var arr = ['hey', 'nay', 'wey'];
var let = arr.split(' ');
console.log(let);
1
var names = 'Harry ;Fred Barney; Helen Rigby ; Bill Abel ;Chris Hand ';

console.log(names);

var re = /\s*(?:;|$)\s*/;
var nameList = names.split(re);

console.log(nameList);
4
<script>  
// JavaScript Program to illustrate split() function  
  
function func() {  
    //Original string  
    var str = 'Geeks for Geeks'
    var array = str.split("for");  
    document.write(array);  
}  
  
func();  
</script>  
-1
// It essentially SPLITS the sentence inserted in the required argument
// into an array of words that make up the sentence.

var input = "How are you doing today?";
var result = input.split(" "); // Code piece by ZioTino

// the following code would return as
// string["How", "are", "you", "doing", "todaY"];
0

New to Communities?

Join the community