Appearance
How to Split a String Breaking at a Particular Character in JavaScript
In this tutorial, you will find the easiest ways of splitting the string in small chunks breaking at a particular character.
For example, you have the following string:
jack brown~132 Street~Apt 20~New Jersey~NJ~12345
For splitting the strings, we should use the split() method like this:
Javascript split method
Output appears here after Run.
According to ECMAScript6, the cleanest way is destructing arrays in the following way:
Javascript split method
Output appears here after Run.
The split() Method
The split() method cuts the string into substrings, puts them into an array, and returns the array. The division is accomplished by searching for a pattern, where it is provided as the first parameter in the call of the method.