explode string in javascript code example

Example 1: js explode equivalent

//Loading the variable
var mystr = '0000000020C90037:TEMP:data';

//Splitting it with : as the separator
var myarr = mystr.split(":");

//Resulting array structure
myarr = ['0000000020C90037', 'TEMP', 'data'];

Example 2: javascript explode

//split into array of strings.
var str = "Well, how, are , we , doing, today";
var res = str.split(",");

Example 3: javascript 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"]

Example 4: js string to array

var myString = 'no,u';
var MyArray = myString.split(',');//splits the text up in chunks

Example 5: js string explode

str.split(';');

Example 6: split() javascript

let countWords = function(sentence){
    return sentence.split(' ').length;
}

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

//result will be '4'(for words in the sentence)

Tags:

Java Example