0
Q:

in javascript how to split string

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']
*
*/
5
// Split string into an array of strings
const path = "/usr/home/chucknorris"
let result = path.split("/")
console.log(result)
// result
// ["", "usr", "home", "chucknorris"]
let username = result[3]
console.log(username)
// username
// "chucknorris"
6
var str = 'It iS a 5r&e@@t Day.'
var array = str.split(" ");
print(array);

var str = 'It iS a 5r&e@@t Day.'
var array = str.split(" ",2);
print(array);
6
var myString = "Hello World!";

// splitWords is an array
// [Hello,World!]
var splitWords = myString.split(" ");

// e.g. you can use it as an index or remove a specific word:
var hello = splitWords[splitWords.indexOf("Hello")];
1
<script>  
// JavaScript Program to illustrate split() function  
  
function func() {  
    //Original string  
    var str = 'Geeks for Geeks'
    var array = str.split("for");  
    document.write(array);  
}  
  
func();  
</script>  
-1
strName.split(); // My code
0

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

var res = str.split(" ");
 
7

New to Communities?

Join the community