Q:

javascript explode

//split into array of strings.
var str = "Well, how, are , we , doing, today";
var res = str.split(",");
29
// 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 myString = 'no,u';
var MyArray = myString.split(',');//splits the text up in chunks
11
	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 = "How are you doing today?";

var res = str.split(" ");
 
7
//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'];
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
str.split(separator/*, limit*/)

/*Syntax explanation -----------------------------
Returns an array of strings seperated at every 
point where the 'separator' (string or regex) occurs. 
The 'limit' is an optional non-sub-zero integer. 
If provided, the string will split every time the 
separator occurs until the array 'limit' has been reached.
*/

//Example -----------------------------------------
const str = 'I need some help with my code bro.';

const words = str.split(' ');
console.log(words[6]);
//Output: "code"

const chars = str.split('');
console.log(chars[9]);
//Output: "m"

const limitedChars = str.split('',10);
console.log(limitedChars);
//Output: Array ["I", " ", "n", "e", "e", "d", " ", "s", "o", "m"]

const strCopy = str.split();
console.log(strCopy);
//Output: Array ["I need some help with my code bro."]
0

New to Communities?

Join the community