How do I split a string in JavaScript?

To split a string in JavaScript, you can use the string.split(separator, limit) method. The split() method is used to split the given string into an array of strings using the "separator" as a delimiter. The second parameter determines how many times to divide the matching value. If no limit is specified, the string will be split into all matching values. The split() method returns a new array without changing the original string. Besides the split() method, you can split a string using Regular Expressions. In this Split a String in JavaScript example, we are splitting a string using the split() method. An example of splitting a string using Regular Expressions in JavaScript is shown below. Click Execute to run the JavaScript Split String Example online and see the result.
Loading...