How to split a string in JavaScript

Today we will show you how to split a string in JavaScript. Here we will use the split() function to explode or split a string in JavaScript.

The split() function has an optional parameter called separator. The separator can be a simple string or it can be a regular expression.

The split function returns an array that contains all the subparts as ordered array items.

Example 1: Splitting the string based on the single space

Example 2: Splitting the string based on the -

Example 3: Split a string with multiple separators

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

1 Response

  1. Steve G. says:

    Nice Article! Keep posting.

Leave a Reply

Your email address will not be published. Required fields are marked *