Problem:
Many of the time we require to get particular portion of the string for further modification. At this time we need to split particular sting.
Solution:
In JavaScript we can use split() method with regular expression to split sting and get desired results. Let's take a look at following given string.
Many of the time we require to get particular portion of the string for further modification. At this time we need to split particular sting.
Solution:
In JavaScript we can use split() method with regular expression to split sting and get desired results. Let's take a look at following given string.
first second third fourth fifth sixth Seventh
"\s" is a regular expression which matches spaces, tabs and new line etc. "\s+" regular expression will match multiple occurrence of the white space and tabs.
var input = "first second third fourth fifth sixth Seventh "; var output = input.split(/\s+/); console.log(output);
Output:
Output will be a array and it will look something like following image.
No Comment to " JavaScript - Spilit string by single or multiple white space "