Hi Friends đź‘‹,
Welcome To Infinitbility! ❤️
To explode string in javascript, use split()
method it will explode your string based upon your parameter you have passed in a split()
method. let’s take a example
The split() method divides a String into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method’s call.
In the following example, we can able explode or split string by every char, space, and your desired string.
1const str = 'Hear about the new restaurant called Karma, There’s no menu: You get what you deserve';23// explode by every char4str.split('') // ['H', 'e', 'a', 'r', ' ', 'a', 'b', 'o', 'u', 't', ' ', 't', 'h', 'e', ' ', 'n', 'e', 'w', ' ', 'r', 'e', 's', 't', 'a', 'u', 'r', 'a', 'n', 't', ' ', 'c', 'a', 'l', 'l', 'e', 'd', ' ', 'K', 'a', 'r', 'm', 'a', ',', ' ', 'T', 'h', 'e', 'r', 'e', '’', 's', ' ', 'n', 'o', ' ', 'm', 'e', 'n', 'u', ':', ' ', 'Y', 'o', 'u', ' ', 'g', 'e', 't', ' ', 'w', 'h', 'a', 't', ' ', 'y', 'o', 'u', ' ', 'd', 'e', 's', 'e', 'r', 'v', 'e']56// explode by space7str.split(' ') // ['Hear', 'about', 'the', 'new', 'restaurant', 'called', 'Karma,', 'There’s', 'no', 'menu:', 'You', 'get', 'what', 'you', 'deserve']89// explode by comma10str.split(',') // ['Hear about the new restaurant called Karma', ' There’s no menu: You get what you deserve']
Today, I’m going to show you How do i explode string in javascript, as above mentioned here, I’m going to use split()
method to explode string via desired seprator.
Let’s start today’s tutorial how do you explode string in javascript?
In this example, we will do
- Take example of split string by char
- Take example of split string by space
- Take example of split string by comma
1// Take example of split string by char2let str1 = "infinitbility";3str1 = str1.split('');4console.log(str1); // ['i', 'n', 'f', 'i', 'n', 'i', 't', 'b', 'i', 'l', 'i', 't', 'y']56// Take example of split string by space7let str2 = "Infinitbility want to make differance";8str2 = str2.split(' ');9console.log(str2); // Â ['Infinitbility', 'want', 'to', 'make', 'differance']1011// Take example of split string by comma12let str3 = "infinitbility,aguidehub,sortoutcode";13str3 = str3.split(',');14console.log(str3); // ['infinitbility', 'aguidehub', 'sortoutcode']
In the above exampls, we have taken multiple string example and explode by diferant parameters, Let’s check the output.

I hope it’s help you, All the best 👍.
Follow me on Twitter
Join our email list and get notified about new content
No worries, I respect your privacy and I will never abuse your email.
Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.