Expression.split() js code example
Example 1: node js split
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);
Example 2: javascript split regex
str.split(separator)
const str = 'I need some help with my code bro.';
const words = str.split(' ');
console.log(words[6]);
const chars = str.split('');
console.log(chars[9]);
const limitedChars = str.split('',10);
console.log(limitedChars);
const strCopy = str.split();
console.log(strCopy);