Check out example codes for "split string". It will help you in understanding the concepts better.
Code Example 1
Split string in javascript
Code Example 2
var input = "How are you doing today?";
var result = input.split(" ");
// result is string[] {"How", "are", "you", "doing", "today?"}
Code Example 3
var str = 'It iS a 5r&[email protected]@t Day.'
var array = str.split(" ");
print(array);
var str = 'It iS a 5r&[email protected]@t Day.'
var array = str.split(" ",2);
print(array);
Code Example 4
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);
Code Example 5
Scanner in=new Scanner(System.in);
String input=in.nextLine();
String[] word=input.split(" ");
Code Example 6
const str = 'The quick brown fox jumps over the lazy dog.';
const words = str.split(' ');
console.log(words[3]);
// expected output: "fox"
const chars = str.split('');
console.log(chars[8]);
// expected output: "k"
const strCopy = str.split();
console.log(strCopy);
// expected output: Array ["The quick brown fox jumps over the lazy dog."]
Learn ReactJs, React Native from akashmittal.com