split syntax js code example

Example 1: string split javascript

var myString = "An,array,in,a,string,separated,by,a,comma";
var myArray = myString.split(",");
/* 
*
*  myArray :
*  ['An', 'array', 'in', 'a', 'string', 'separated', 'by', 'a', 'comma']
*
*/

Example 2: js string to array

str = 'How are you doing today?';
console.log(str.split(' '));

>> (5) ["How", "are", "you", "doing", "today?"]

Example 3: how to split a string in javascript

strName.split(); // My code

Example 4: how to saperate string to array

Scanner in=new Scanner(System.in);
		String input=in.nextLine();
		String[] word=input.split(" ");

Tags:

Java Example