JavaScript String split() Method

## JavaScript Reference

Overview

## JavaScript Objects

JS Array JS Boolean JS Date JS Math JS Number JS String JS RegExp JS Global

## Browser Objects

Window Navigator Screen History Location

## HTML DOM Objects

DOM Document DOM Elements DOM Attributes DOM Events

## HTML Objects

DOM Anchor DOM Area DOM Base DOM Body DOM Button DOM Form DOM Frame/IFrame DOM Frameset DOM Image DOM Input Button DOM Input Checkbox DOM Input File DOM Input Hidden DOM Input Password DOM Input Radio DOM Input Reset DOM Input Submit DOM Input Text DOM Link DOM Meta DOM Object DOM Option DOM Select DOM Style DOM Table DOM td / th DOM tr DOM Textarea

# JavaScript String split() Method

JavaScript String Object

## Example

Split a string into an array of substrings:

var str = "How are you doing today?";
var res = str.split(" ");

The result of res will be an array with the values:

How,are,you,doing,today?
Try it yourself »

## Definition and Usage

The split() method is used to split a string into an array of substrings, and returns the new array.

Tip: If an empty string ("") is used as the separator, the string is split between each character.

Note: The split() method does not change the original string.

## Browser Support

The split() method is supported in all major browsers.

## Syntax

string.split(separator,limit)

## Parameter Values

Parameter | Description
--- | ---
separator | Optional. Specifies the character, or the regular expression, to use for splitting the string. If omitted, the entire string will be returned (an array with only one item)
limit | Optional. An integer that specifies the number of splits, items after the split limit will not be included in the array

## Return Value

Type | Description
--- | ---
Array | An array containing the splitted values

## Technical Details

JavaScript Version: | 1.1

## More Examples

## Example

Omit the separator parameter:

var str = "How are you doing today?";
var res = str.split();

The result of res will be an array with only one value:

How are you doing today?
Try it yourself »

## Example

Separate each charater, including white-space:

var str = "How are you doing today?";
var res = str.split("");

The result of res will be an array with the values:

H,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y,?
Try it yourself »

## Example

Use the limit parameter:

var str = "How are you doing today?";
var res = str.split(" ",3);

The result of res will be an array with only 3 values:

How,are,you
Try it yourself »

## Example

Use a letter as a separator:

var str = "How are you doing today?";
var res = str.split("o");

The result of res will be an array with the values:

H,w are y,u d,ing t,day?
Try it yourself »

JavaScript String Object

## Your suggestion:

Your E-mail (optional):

Page address:

Description:

Close [X]

## Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

## WEB HOSTING

Best Web Hosting UK Reseller Hosting Wow! $5 SSD Hosting

## WEB BUILDING

Download XML Editor
FREE Website BUILDER FREE Website Creator

## WEB RESOURCES

Web Statistics Web Validation

## SHARE THIS PAGE