javascript split() method


  Translation results:

英[splɪt] 美[splɪt]

vt.Split;separate;<slang>(quickly) leave;share

n.divide;disagreement;crack;split

vi. Separated, split

Third person singular: splits Plural: splits Present participle: splitting Past tense: split Past participle: split

javascript split() methodsyntax

Function: Split a string into a string array.

Syntax: stringObject.split(separator,howmany)

Parameters: separator Required. A string or regular expression to split the stringObject from where specified by this parameter. Howmany Optional. This parameter specifies the maximum length of the returned array. If this parameter is set, no more substrings will be returned than the array specified by this parameter. If this parameter is not set, the entire string will be split regardless of its length.​

Return: A string array. The array is created by splitting the string stringObject into substrings at the boundaries specified by separator . The strings in the returned array do not include the separator itself. However, if separator is a regular expression that contains subexpressions, then the returned array includes strings that match those subexpressions (but not text that matches the entire regular expression).

Note: If the empty string ("") is used as a separator, each character in the stringObject will be split. String.split() performs the opposite operation of Array.join .

javascript split() methodexample

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">

    var str="How are you doing today?"

    document.write(str.split(" ") + "<br />")
    document.write(str.split("") + "<br />")
    document.write(str.split(" ",3))

</script>

</body>
</html>

Run instance »

Click the "Run instance" button to view the online instance

Popular Recommendations

Home

Videos

Q&A