0
Q:

.split javascript

var myString = "An,array,in,a,string,separated,by,a,comma";
var myArray = myString.split(",");
/* 
*
*  myArray :
*  ['An', 'array', 'in', 'a', 'string', 'separated', 'by', 'a', 'comma']
*
*/
5
// Split string into an array of strings
const path = "/usr/home/chucknorris"
let result = path.split("/")
console.log(result)
// result
// ["", "usr", "home", "chucknorris"]
let username = result[3]
console.log(username)
// username
// "chucknorris"
6
// 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

New to Communities?

Join the community