Answers for "split string on ,"

21

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"]
Posted by: Guest on May-01-2020
3

split()

const str = 'The quick brown fox jumps over the lazy dog.';
console.log(str.split(''));
console.log(str.split(' '));
console.log(str.split('ox'));
> Array ["T", "h", "e", " ", "q", "u", "i", "c", "k", " ", "b", "r", "o", "w", "n", " ", "f", "o", "x", " ", "j", "u", "m", "p", "s", " ", "o", "v", "e", "r", " ", "t", "h", "e", " ", "l", "a", "z", "y", " ", "d", "o", "g", "."] 
> Array ["The", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog."] 
> Array ["The quick brown f", " jumps over the lazy dog."]


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();
Posted by: Guest on April-19-2021
0

string split method

var str = "How are you doing today?";

var res = str.split(" ", 3);
Posted by: Guest on April-03-2021
0

split string

String[] result = "this is a test".split("\\s");
     for (int x=0; x<result.length; x++)
         System.out.println(result[x]);
Posted by: Guest on June-11-2021
-2

how to saperate string to array

Scanner in=new Scanner(System.in);
		String input=in.nextLine();
		String[] word=input.split(" ");
Posted by: Guest on May-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language