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);
/* split methods splits string object into array of strings
and join method changes element of array into a string */
const name= "Shirshak Kandel"
const nameWithDash=name.split(" ").join("-")
console.log(nameWithDash);//Shirshak-kandel
function splitString(stringToSplit, separator) {
var arrayOfStrings = stringToSplit.split(separator);
console.log('The original string is: "' + stringToSplit + '"');
console.log('The separator is: "' + separator + '"');
console.log('The array has ' + arrayOfStrings.length + ' elements: ' + arrayOfStrings.join(' / '));
}
var tempestString = 'Oh brave new world that has such people in it.';
var monthString = 'Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec';
var space = ' ';
var comma = ',';
splitString(tempestString, space);
splitString(tempestString);
splitString(monthString, comma);
let countWords = function(sentence){
return sentence.split(' ').length;
}
console.log(countWords('Type any sentence here'));
//result will be '4'(for words in the sentence)
var myString = "Hello World!";
// splitWords is an array
// [Hello,World!]
var splitWords = myString.split(" ");
// e.g. you can use it as an index or remove a specific word:
var hello = splitWords[splitWords.indexOf("Hello")];
// Split a string into an array of substrings:
var String = "Hello World";
var Array = String.split(" ");
console.log(Array);
//Console:
//["Hello", "World"]
///*The split() method is used to split a string into an array of substrings, and returns the new array.*/
const string = "this is the array that we want to split";
var splittedString = string.split(" ") //place the separator as a parameter
/* splittedString:
* ['this', 'is', 'the', 'array', 'that', 'we', 'want', 'to', 'split']
*/
//The split() method takes a pattern and divides a String into an ordered list of substrings by searching for the pattern, puts these substrings into an array, and returns the array.
const str1 = 'The quick brown fox jumps over the lazy dog.';
const words = str1.split(' ');
console.log(words[3]);
// expected output: "fox"
const chars = str1.split('');
console.log(chars[8]);
// expected output: "k"
const strCopy = str1.split();
console.log(strCopy);
// expected output: Array ["The quick brown fox jumps over the lazy dog."]
// 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"];
var test= "Hi I am a fullstack developper";
var result= test.split("l");
//return:
// [Hi I am a fu,,stack deve,lopper]
/*the split methode replace the (letter/symbole) into the
brackets to "," and transform it to array.*/