JavaScript String split() Method

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP







<!--
main_leaderboard, all: [728,90][970,90][320,50][468,60]
-->



JavaScript String split() Method



Previous
JavaScript String Reference
Next

<!--

❮ JavaScript String Reference

-->


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 »

More "Try it Yourself" examples below.



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














Method
split() Yes Yes Yes Yes Yes

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




<!--
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]
-->




Technical Details






Return Value: An Array, containing the splitted values
JavaScript Version: ECMAScript 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 character, 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 »



Previous
JavaScript String Reference
Next

<!--

❮ JavaScript String Reference

-->

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)