string splitting javascript 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: split javascript

var str = "12,15,16,78,59";
var res = str.split(",");
console.log(res[0]); // result: 12
console.log(res[2]); // result: 16

Example 3: javascript split

var arr = ['hey', 'nay', 'wey'];
var let = arr.split(' ');
console.log(let);

Example 4: how to saperate string to array

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